如何增加JFileChooser的大小? [英] How to increase the size of a JFileChooser?
问题描述
我正在编写一个需要在屏幕分辨率非常高的设备上运行的Java应用程序。我需要显示的唯一UI组件是JFileChooser。
I'm writing a Java app that needs to run on a device with a very high screen resolution. The only UI component that I need to display is a JFileChooser.
由于屏幕分辨率太高,FileChooser显得太小。是否有一个简单的命令我可以使它变大?理想情况下,我希望保持组件的比例相同,以便图标的增长与文本一样多。
Since the screen resolution so high, the FileChooser appears too small. Is there a simple command I can use to make it bigger? Ideally, I'd like to keep the proportions of the components the same, so that the icons grow just as much as the text.
此外,任何更改都很重要仅修改我的应用程序。改变图形大小的全局方法,例如使用较低分辨率或更改系统范围的字体大小,对我来说不是一种选择。
Also, it's important that any changes modify only my application. A global approach to changing the size of the graphics, like using a lower resolution, or changing a system-wide font size, isn't an option for me.
任何想法?
推荐答案
这个类工作正常,可以调整JFileChooser窗口和字体的大小。
This class works fine, both resizing JFileChooser window and fonts.
public class JFileChooserArqs {
private Font font = new Font("monospaced",Font.BOLD,16);
private String fileName;
public JFileChooserArqs(String title)
{
fileName = null;
JFileChooser fc = new JFileChooser(".");
fc.setPreferredSize(new Dimension(800,600));
fc.setDialogTitle(title);
setFileChooserFont(fc.getComponents());
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
fileName = fc.getSelectedFile().getAbsolutePath();
}
}
private void setFileChooserFont(Component[] comp)
{
for(int x = 0; x < comp.length; x++)
{
if(comp[x] instanceof Container) setFileChooserFont(((Container)comp[x]).getComponents());
try{comp[x].setFont(font);}
catch(Exception e){}//do nothing
}
}
public String obtemNomeArquivo() {
return fileName;
}
}
这篇关于如何增加JFileChooser的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!