有没有办法更改 JFileChooser 中特定文件条目的样式(字体颜色)?

发布于 2025-01-12 06:36:35 字数 670 浏览 3 评论 0原文

我目前正在开发一个小型应用程序,我有一个特定的文件列表,并且我有它们的绝对路径。我想知道是否有一种方法可以专门针对 JFileChooser 中的文件条目来更改其字体颜色(我猜是使用 setForeground ),以及是否有在更改目录时执行此操作的方法(我猜是在 Listener 回调中)

这是我生成 JFileChooser 的代码部分:

JFileChooser fileChooser = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("CSV files", new String[] {"csv"});
fileChooser.setFileFilter(filter);
fileChooser.setCurrentDirectory(new File(dirname));
int result = fileChooser.showOpenDialog(parent);
if (result == JFileChooser.APPROVE_OPTION) {
    File selectedFile = fileChooser.getSelectedFile();
    Visualizer.loadCase(selectedFile.getAbsolutePath());
}

感谢您的帮助!

I'm currently working on a small app, and I have a list of files that are specific, and I have their abosolute path. I was wondering if there was a way to specifically target a file entry in a JFileChooser to change its font color (I'd guess with setForeground), and if there is a way to do so while changing directories (in a Listener callback I'd guess)

Here is the section of code where I generate the JFileChooser :

JFileChooser fileChooser = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("CSV files", new String[] {"csv"});
fileChooser.setFileFilter(filter);
fileChooser.setCurrentDirectory(new File(dirname));
int result = fileChooser.showOpenDialog(parent);
if (result == JFileChooser.APPROVE_OPTION) {
    File selectedFile = fileChooser.getSelectedFile();
    Visualizer.loadCase(selectedFile.getAbsolutePath());
}

Thanks for your help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文