欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

给JTextField添加tooltip,jtextfieldtooltip,package cn.o

来源: javaer 分享于  点击 32427 次 点评:117

给JTextField添加tooltip,jtextfieldtooltip,package cn.o


package cn.outofmemory.snippets.desktop;import java.awt.FlowLayout;import javax.swing.JFrame;import javax.swing.JTextField;public class CreateJTextFieldWithTooltip extends JFrame {    private static final long serialVersionUID = 1L;    public CreateJTextFieldWithTooltip() {        // set flow layout for the frame        this.getContentPane().setLayout(new FlowLayout());        // create JTextField        JTextField field = new JTextField();        field.setText("Java Code Geeks");        // Registers the text to display in a tool tip.        // The text displays when the cursor lingers over the component.        field.setToolTipText("This is the textfield's tooltip");        String tooltipText = field.getToolTipText();        System.out.println("Tooltip Text: " + tooltipText);        // add textfield to frame        add(field);    }    private static void createAndShowGUI() {        //Create and set up the window.        JFrame frame = new CreateJTextFieldWithTooltip();        //Display the window.        frame.pack();        frame.setVisible(true);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    }    public static void main(String[] args) {        //Schedule a job for the event-dispatching thread:        //creating and showing this application's GUI.        javax.swing.SwingUtilities.invokeLater(new Runnable() {            public void run() {                createAndShowGUI();             }        });    }}
相关栏目:

用户点评