[英]Tool tip in gui not displaying?
我正在使用.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
}
}
嘗試添加getRootPane()。setToolTipText(“ String”); 這將確保將鼠標懸停在JFrame上時顯示工具提示
import java.awt.FlowLayout;
import javax.swing.JFrame; window, like minimize
import javax.swing.JLabel;
public class moregui extends JFrame{
private JLabel item1;
public moregui(){ //Constructor
super("This is the title bar"); //These are all imported methods
getRootPane().setToolTipText("Hovering over window");
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
}
}
這是正確的代碼。 嘗試將鼠標懸停更長的時間。
JPanel panel = new JPanel();
panel.setToolTipText("ToolTIp");
contentPane.add(panel, BorderLayout.NORTH);
JLabel lblLabel = new JLabel("Label");
panel.add(lblLabel);
如果您遇到其他問題,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.