当前位置: 首页 > 面试题库 >

如何更改Java程序单个部分的外观

商茂勋
2023-03-14
问题内容

因此,我正在制作一个程序选择工具,目前,我只喜欢Java外观就喜欢所有外观。我唯一想更改的是Windows的JFileChooser外观。当我打电话给filechooser并告诉它更改外观时,它什么也没做。当我在程序启动时调用它时,它会使按钮显得糟糕。所以谷歌没有任何东西,我不知道如何使它工作。请帮忙!让我知道哪些代码将是相关且有用的。提前致谢!

编辑:所以这是JFileChooser及其启动方式的一些代码关系:

public class Start(){
    public static JButton assignButton = new JButton(new AbstractAction(
        "Assign") {
    public void actionPerformed(ActionEvent e) {
        AssignWindow.run();
    }
});
}

public class AssignmentWindow(){
   public static void run() {
    Dialogs.assignmentInfo();

    bgImage = aw.getImage("files/background.png");

            //aw is the object of this class
    aw.makeFrame();     //makes the jframe for all the buttons to sit.
    aw.setGraphics();   //assigns a different graphics variable

    aw.fileChooser();
}

public void fileChooser() {
    JFileChooser jfc = new JFileChooser();
    jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

            // here is where i want to set the look and feel....

    if (jfc.showDialog(null, "Select") == JFileChooser.APPROVE_OPTION) {
        File file = jfc.getSelectedFile();
        fileDir = file.getPath();
    } else {
        Dialogs.msg("You cancled selecting a file. Returning to file frame...");
        AssignWindow.destroy();
    }
}
}

问题答案:

所有需要做的就是在创建JFileChooser对象时更改UIManager,然后将其设置回之前的状态,或者您可以仅捕获Exception,但这是一个不好的做法。

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);
}


 类似资料:
  • 问题内容: 我想从Java应用程序启动外部第三方应用程序。我的Java应用程序运行时,此外部应用程序应始终运行。 从时间到时间(这取决于用户交互)我的Java应用程序应该能够通过阅读和写这个外部应用程序和。 我怎样才能做到这一点? 问题答案: 是前应用程序本机代码还是其他Java程序?如果是本机代码,请查看http://download.oracle.com/javase/1.5.0/docs/a

  • 问题内容: 如何在Macintosh平台上使用Java更改程序的Dock图标?我听说过使用Apple的Java库(在Mac平台上提供了某种额外的支持),但是我还没有找到一些实际的例子。 问题答案: Apple eAWT提供了Application类,该类允许更改应用程序的停靠图标。

  • 我正试图在应用程序处于退出状态时从firebase保存一个通知到redux。 但是我需要在app.js中这样做,当我甚至不在组件上时,我如何分派redux操作呢? 这就是我要做的

  • 我有一个名为“ParkPhotos.txt”的文件,里面有一些公园的12个名字,例如“AmericanMosao_photo.jpg”。我想把“_photo.jpg”改成“_info.txt”,但我很挣扎。在代码中,我能够读取该文件,但我不确定如何替换它。

  • 本文向大家介绍Java如何基于ProcessBuilder类调用外部程序,包括了Java如何基于ProcessBuilder类调用外部程序的使用技巧和注意事项,需要的朋友参考一下 这篇文章主要介绍了Java如何基于ProcessBuilder类调用外部程序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1. demo1 2. demo02 以上就