4

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?

dB'
  • 7,838
  • 15
  • 58
  • 101
  • 1
    good question :-) Unfortunately, the answer is so much work that it amounts to no-way: while you could change the size of the dialog, that wouldn't increase the fonts used. Even if you change the fonts (could be done in the UIManager), the icons would still be small (could be changed to custom icons in the UIManager as well, though) – kleopatra Jan 25 '12 at 10:29

4 Answers4

5

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;
    }
}
ave4496
  • 2,950
  • 3
  • 21
  • 48
user2773791
  • 59
  • 1
  • 1
2

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
}
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
PeGiannOS
  • 227
  • 4
  • 19
1

You need to choose suitable layouts to design the user interface. Have a look at CodeRanch thread.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • Thanks for this. I just realized that my original question was a bit too general. I'm actually just trying to resize a single window -- namely a JFileChooser. I've just edited the question heavily to reflect this. I'd prefer to use the default JFileChooser layout rather than designing my own. Do I have any options besides changing the layout? – dB' Jan 25 '12 at 02:51
  • @dB' It seems that `JFileChooser` exposes `setSize(int width, int height)` method. Have you tried it? – ee. Jan 25 '12 at 03:20
1

I was going to suggest adding the JFileChooser to a container having a suitable layout, as @AVD suggests. For example, ImageDisplay adds the chooser to BorderLayout.WEST where it's free to grow vertically while adopting the UI delegate's preferred width. Before you abandon that approach, verify that you are not inadvertently defeating that design feature.

If you really need control over the display characteristics of the chooser's subcomponents, you may want to look at these variations of FileBrowser.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045