修改SeaGlass JComponents

时间:2014-01-10 16:51:54

标签: java swing look-and-feel

我正在尝试创建一个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();
        }
    }
}

1 个答案:

答案 0 :(得分:3)

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

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