1.11M Members

Using frame.pack() for resizing JFrame

 
0
 

Hi!

The problem is connected with using frame.pack(). So, let's say there is JFrame: frame. Depending on the option selected from JComboBox, the content and size of JFrame should change. Everything works perfectly in NetBeans (!!!). However, if I try to run the JAR file, then the size of JFrame does not change after selecting different options from JComboBox. It remains equal to the size that corresponds to the first option selected. Why that could happen? I'm not sure that I've explain clearly. In case of any indistinctness, I could clarify the problem aspects.

Some main parts of the code are shown below. Please, help me with some advice, because I cannot understand the reason of this problem. Thanks!

public class Folder extends JDialog {

    public Folder()
    {
        frame = new JFrame();
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);

        panel = new JPanel(new MigLayout());

	cmbFolderType = new JComboBox(folderTypes);
        cmbFolderType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if ((String)cmbFolderType.getSelectedItem() == folderTypes[0]) {
                    layoutOrgFolder();
                } else if ((String)cmbFolderType.getSelectedItem() == folderTypes[1]) {
                    layoutDocFolder();
                }
            }
        });

        layoutOrgFolder();
        updateTree();

        //frame.pack();
        //frame.setLocationRelativeTo(null);

    }

...

    private void layoutOrgFolder() {
        panel.removeAll();
        panel.updateUI();

        panLeft = new JPanel(new MigLayout("fill", "","[]5px[]"));
...
        panLeft.add(label1); panLeft.add(cmbFolderType, "wrap");
        panLeft.add(label2); panLeft.add(text1, "wrap");
        panLeft.add(label3); panLeft.add(text2, "wrap");
        panLeft.add(butAddOrgFolder); panLeft.add(butCancelAddOrgFolder);

...

        panel.add(panLeft);

        frame.add(panel);
        
        frame.pack();
        frame.setLocationRelativeTo(null);

    }

    private void layoutDocFolder() {
        panel.removeAll();
        panel.updateUI();

        panLeft = new JPanel(new MigLayout("fill", "","[]5px[]"));
        panMiddle = new JPanel(new MigLayout("fill"));
        panRight = new JPanel(new MigLayout("fill"));

 ...
      
        panLeft.add(label1); panLeft.add(cmbFolderType, "wrap");
        panLeft.add(label2); panLeft.add(text1, "wrap");
        panLeft.add(label3); panLeft.add(text2, "wrap");
        panLeft.add(label4); panLeft.add(cmbFormType, "wrap");
        panLeft.add(label5); panLeft.add(text4, "wrap");
        
        panLeft.add(butAddDocFolder); panLeft.add(butCancelAddDocFolder);

        attrTable = new JTable();
        final QTableModel tableModel = new QTableModel(url, databasename, login, password);
        attrTable.setModel(tableModel);
        attrTable.setColumnSelectionAllowed (false);
        attrTable.setRowSelectionAllowed(true);
        attrTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        JScrollPane jScrollPane1 = new JScrollPane(attrTable, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        int deltax = (int) (0.4 * SystClasses.Form.panfortab.getPreferredSize().width);
        int deltay = (int) (0.25 * SystClasses.Form.panfortab.getPreferredSize().height);
        jScrollPane1.setPreferredSize(new Dimension(deltax, deltay));
        panMiddle.add(jScrollPane1);

        panRight.add(butUp, "wrap"); panRight.add(butDown);

        panel.add(panLeft);
        panel.add(panMiddle);
        panel.add(panRight);

        frame.add(panel);
        frame.pack();
        frame.setLocationRelativeTo(null);

    }
...
}
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article