我正在使用.setToolTipText组件,以便文本"当您将鼠标悬停在它上面时会显示该文本"当鼠标悬停在窗口上时显示出来。目前,除工具提示外,其他所有工作都有效。现在,工具提示仅在字词上方悬停时显示,当我将鼠标悬停在窗口本身上时,如何显示它?这是代码:
这是主要课程:
import javax.swing.JFrame;
class evenmoregui{
public static void main (String[ ] args){
moregui guiobject = new moregui();
guiobject.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Makes the program terminate when the x is clicked
guiobject.setSize(275,180); //This is the size
guiobject.setVisible(true); //Means it should show up, actually puts the window on screen
}
}
这是具有实际.setToolTip部分的类:
import java.awt.FlowLayout; //Make it so the windows don't overlap, it just formats the windows properly
import javax.swing.JFrame; //Gives you all the windows features in the window, like minimize
import javax.swing.JLabel; //Allows text and simple images on window
public class moregui extends JFrame { //JFrame gives you all the basic windows features.
private JLabel item1;
public moregui(){ //Constructor
super("This is the title bar"); //These are all imported methods
setLayout(new FlowLayout()); //Gives default layout
item1 = new JLabel("This is a sentence"); //Text on the screen
item1.setToolTipText("This will show up when you hover over it");
add(item1); //Adds item1 into window
}
}
答案 0 :(得分:2)
尝试添加getRootPane()。setToolTipText(" String"); 这将确保在JFrame上悬停时显示工具提示
$.ajax({
url : ajaxOverallUrl,
data : ajaxDataLink,
dataType : 'json',
type : 'get',
async : true,
success : function(data) {},
complete: function a{//this contains ajax request 2},
function b(){//this contains ajax request 3}
});
答案 1 :(得分:1)
这是一个正确的代码。尝试更长时间地悬停在它上面。
JPanel panel = new JPanel();
panel.setToolTipText("ToolTIp");
contentPane.add(panel, BorderLayout.NORTH);
JLabel lblLabel = new JLabel("Label");
panel.add(lblLabel);
如果您遇到更多问题,请告诉我。