编程语言
首页 > 编程语言> > java-修改SeaGlass JComponents

java-修改SeaGlass JComponents

作者:互联网

我正在尝试创建JTextField的变体,使其看起来更像是“搜索”字段,我在SeaGlass网站上看到了此内容,但在实现它时遇到了麻烦…外观本身感觉很完美,但是我无法访问JTextField.variant方法…我正在测试以下类:

public class Stuff extends JFrame {

    JTextArea text;
    JTextField field;

    public Stuff() {
        text = new JTextArea("something");
        text.setEditable(false);
        field = new JTextField(20).variant("search");            
        setLayout(new FlowLayout());            
        add(text);
        add(field);            
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(600, 300);
    }
}

并在此类中调用它:

public class SeaGlassTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
            new Stuff();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

解决方法:

修复!为了将来参考,您需要的代码是:

field.putClientProperty("JTextField.variant", "search");

标签:look-and-feel,swing,java
来源: https://codeday.me/bug/20191122/2058362.html