开发者

Mixing look and feel

So far I have this

public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            UIManager.getBorder("design");//change look and feel here?
       开发者_如何学Go } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Nimbus isn't available");
        }
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                design GUI = new design();
                GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                GUI.setVisible(true);
            }
        });
    }

I'm trying to make the main look and feel nimbus, but change the titled border to windows.

My border is this:

contentPanel.setBorder(new TitledBorder("Downloader"));

Is it possible to do? If it is can someone point me where to look? I'm so confused right now. :\

Thanks.


I've done it. You have to create parts of the UI, and then call UIManager.setLookAndFeel() to change the look & feel, and then create the other parts. It's more like a hack.


When a Component is created, the current LookAndFeel will be used to display that Component.


I know I am late but I think someone might be use this it is kind of hack that I use to put multi look and feel to the app: put this the look and feel chooser before initiating the item (before writing = new ...)

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
    | UnsupportedLookAndFeelException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

and then return the UIManager look and feel to the look and feel that it was on before you do this after it as in the example below:

JButton test;
try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
    | UnsupportedLookAndFeelException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
test = new JButton();
try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Mwtal".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
    | UnsupportedLookAndFeelException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Like this only the button test will have the look and feel of the windows and the rest will have look and feel of Metal.

Hope this hack help someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜