Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4416982

JFileChooser does not use its resources to size itself initially

XMLWordPrintable

    • beta
    • x86
    • generic

      Actual behaviour - The JFileChooser is internally setting a fixed size.
           This causes icons and other things to submarine and the dialog size to
           be set wrong. We found this with Japanese but the attached code will
           successfully produce it with the english locale (see image in attachment).


      Expected behaviour - The JFileChooser should have a default size based upon
           the resources that are set - not a fixed size. The following example
           shows things that are not working right.



      > import javax.swing.*;
      > import java.io.File;
      >
      > class X {
      > public static void main(String[] aArgs) {
      >
      > System.err.println(
      > "JFileChooser is broken - notice how the icons and buttons disappear when\n" +
      > "we change the text. This is not an issue for english - but for Japanese\n" +
      > "it is very likely to happen (it did for us)");
      > System.err.println(
      > "The default size of JFileChooser should scale based on the size of \n" +
      > "buttons, and other text.");
      > UIManager.getDefaults().put(
      > "FileChooser.lookInLabelText",
      > "Look In - but make it too long to break the dialog");
      > UIManager.getDefaults().put(
      > "FileChooser.fileNameLabelText",
      > "File Name - but make it too way way way too long to break the dialog");
      >
      > JFileChooser chooser = new JFileChooser(".");
      > chooser.setDialogTitle(
      > "This is a longish sort of title - makes no difference anyway");
      > File lChosen = null;
      > if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
      > System.err.println("opened = " + chooser.getSelectedFile());
      > }
      > System.exit(1);
      > }
      > }

      ** Feb 27 2001 11:37PM Belley,G **
      ###################################################

      ( com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java)
       Here's the code which seems wrong -
          // Preferred and Minimum sizes for the dialog box
          private static int PREF_WIDTH = 425;
          private static int PREF_HEIGHT = 245;
          private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH,
      PREF_HEIGHT);
       
          private static int MIN_WIDTH = 400;
          private static int MIN_HEIGHT = 200;
          private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH,
      MIN_HEIGHT);
       
          private static int LIST_MIN_WIDTH = 400;
          private static int LIST_MIN_HEIGHT = 100;
          private static Dimension LIST_MIN_SIZE = new Dimension(LIST_MIN_WIDTH,
      LIST_MIN_HEIGHT);
       
       
      and

          public Dimension getPreferredSize(JComponent c) {
       return PREF_SIZE;
          }
       
          public Dimension getMinimumSize(JComponent c) {
       return MIN_SIZE;
          }
       
          public Dimension getMaximumSize(JComponent c) {
       return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
          }

      At the very least the preferred size should be based upon the size of
      components. Here's the code which actually shows the dialog - notice how we
      have (from JFileChooser.java)
       
          public int showDialog(Component parent, String approveButtonText) {
               if(approveButtonText != null) {
                   setApproveButtonText(approveButtonText);
                   setDialogType(CUSTOM_DIALOG);
               }
       
              Frame frame = parent instanceof Frame ? (Frame) parent
                    : (Frame)SwingUtilities.getAncestorOfClass(Frame.class,
      parent);
       
              String title = null;
       
               if(getDialogTitle() != null) {
                  title = dialogTitle;
               } else {
               title = getUI().getDialogTitle(this);
           }
       
           dialog = new JDialog(frame, title, true);
           Container contentPane = dialog.getContentPane();
           contentPane.setLayout(new BorderLayout());
           contentPane.add(this, BorderLayout.CENTER);
           dialog.pack();
           dialog.setLocationRelativeTo(parent);
       
           rescanCurrentDirectory();
       
           dialog.show();
           return returnValue;
         }
      ##########################################################

            leifs Leif Samuelsson (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: