栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

向空的JCombobox添加水印

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

向空的JCombobox添加水印

注意:

请查看文本提示,以更完整地实现以下代码,并提供更多功能。


我把一些简单的东西放在一起。我敢肯定你可以整理一下。由于代码可以在JTextField上工作,因此您需要获取组合框的编辑器。我对Glazed列表的实现方式一无所知,所以我只是猜测它会为您工作。

import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import javax.swing.text.*;public class Textprompt extends JLabel    implements FocusListener, documentListener{    private JTextComponent component;    private document document;    public Textprompt(String text, JTextComponent component)    {        this.component = component;        document = component.getdocument();        setText( text );        setFont( component.getFont() );        setBorder( new EmptyBorder(component.getInsets()) );        component.addFocusListener( this );        document.adddocumentListener( this );        component.add( this );    }    public void checkForprompt()    {        if (document.getLength() == 0) setSize( component.getSize() );        else setSize(0, 0);    }//  Implement FocusListener    public void focusGained(FocusEvent e)    {        checkForprompt();    }    public void focusLost(FocusEvent e)    {        setSize(0, 0);    }//  Implement documentListener    public void insertUpdate(documentEvent e)    {        checkForprompt();    }    public void removeUpdate(documentEvent e)    {        checkForprompt();    }    public void changedUpdate(documentEvent e) {}    public static void main(String[] args)    {        JPanel panel = new JPanel();        JTextField tf1 = new JTextField(10);        panel.add(tf1);        JTextField tf2 = new JTextField(10);        panel.add(tf2);        new Textprompt("First Name", tf1);        new Textprompt("Last Name", tf2);        Jframe frame = new Jframe();        frame.setDefaultCloseOperation( Jframe.EXIT_ON_CLOSE );        frame.add(panel);        frame.pack();        frame.setLocationRelativeTo( null );        frame.setVisible(true);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/398262.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号