How to change the look and feel of a single part of a java program

前端 未结 4 679
抹茶落季
抹茶落季 2020-12-18 04:24

So I\'m making a program selection tool, and currently i like the way everything looks with just the java look and feel. the only thing i want to change is the JFileChooser

4条回答
  •  Happy的楠姐
    2020-12-18 05:11

    All that is needed is to change the UIManager while creating the JFileChooser Object, then setting it back to what it was previously, alternatively you could just catch Exception, but that is bad practice.

    public void stuff(){
        JFileChooser chooser = null;
        LookAndFeel previousLF = UIManager.getLookAndFeel();
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            chooser = new JFileChooser();
            UIManager.setLookAndFeel(previousLF);
        } catch (IllegalAccessException | UnsupportedLookAndFeelException | InstantiationException | ClassNotFoundException e) {}
        //Add whatever other settings you want to the method
        chooser.showOpenDialog(frame);
    }
    

提交回复
热议问题