Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the size of a JFileChooser?

Tags:

java

swing

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.

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.

Any ideas?

like image 945
dB' Avatar asked Aug 31 '25 20:08

dB'


2 Answers

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;
    }
}
like image 144
user2773791 Avatar answered Sep 03 '25 10:09

user2773791


I know the answer. Just use chooser.setPreferredSize(new Dimension(int width,int height)); method where chooser is your JFileChooser .

Example:

public class MyFrame extends JFrame(){
  JFileChooser chooser = new JFileChooser();
  chooser.setPreferredSize(new Dimension(800,600));
  //Here show your dialog and do the rest
}
like image 40
PeGiannOS Avatar answered Sep 03 '25 09:09

PeGiannOS