1

I use swingx and miglayout extensions and I having a problem. I have the following code:

public class App {

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            JFrame frame = new JFrame();

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new MigLayout());

            JXPanel keysPanel = new JXPanel();
            JXPanel keysPanelContainer = new JXPanel();
            JScrollPane scrollPane = new JScrollPane(keysPanelContainer,

                    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

            JButton nextButton = new JButton("Next");

            keysPanel.setLayout(new MigLayout());
            keysPanelContainer.setLayout(new MigLayout());
            scrollPane.setBorder(BorderFactory.createEmptyBorder());
            keysPanelContainer.setScrollableHeightHint(ScrollableSizeHint.PREFERRED_STRETCH);

            keysPanelContainer.add(keysPanel, "w 100%, h 100%");
            frame.add(scrollPane, "w 100%, h 100%");
            frame.add(nextButton, "newLine, right");

            frame.setSize(600, 320);
            frame.setLocationRelativeTo(null);

            frame.setVisible(true);
        }
    });

 }
}

And when I run this code, height if my keysPanel increases to infinity. What is wrong in my code ? I need keysPanel height 100%.

Programmer
  • 445
  • 4
  • 12
  • 1. height 100%. == max size in pixels implemented in JPanels API, 2. and this Dimension != infinity, 3. for better help sooner post an SSCCE/MCVE, short, runnable, compilable – mKorbel Jun 06 '15 at 07:42
  • override getPreferredSize for both (missing reason, maybe is there reason for fills one with another and the empty JPanel has Dimension 0x0 == FlowLayout) JPanels (tons posts about here), don't to use setSize/setPreferredSize for MigLayout – mKorbel Jun 06 '15 at 07:46
  • @mKorbel thanks for reply. I edited my post. – Alexey Smirnov Jun 06 '15 at 08:55
  • override [getPreferredScrollableViewportSize](http://stackoverflow.com/a/15914892/714968) - (by trashgod) for JScrollPane then to use JFrame.pack() instead of JFrame.setSize(), override [getPreferredSize](http://stackoverflow.com/a/7229519/714968) - (by kleopatra) for JPanels, both are mentioned, fully described here lots of times (including code in SSCCE/MCVE form) – mKorbel Jun 06 '15 at 12:47

0 Answers0