0

I have a typical IDE style window with a top JMenuBar and JToolBar, a large center console and a bottom status bar.

Here are the main parts of the code:

mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());

JPanel topPanel = new JPanel();
. (JMenuBar and JToolBar)
.

mainPanel.add(topPanel, BorderLayout.NORTH);

cardPanel = new JPanel();
cardPanel.setLayout(cardLayout);
.
.

Dimension minDimension = new Dimension(680, 400);
Dimension maxDimension = new Dimension(750, 800);

JPanel centerPanel = new JPanel();
centerPanel.setMinimumSize(minDimension);
centerPanel.setPreferredSize(minDimension);
centerPanel.setMaximumSize(maxDimension);
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
centerPanel.add(cardPanel);

mainPanel.add(centerPanel, BorderLayout.CENTER);

mainPanel.add(statusBar, BorderLayout.SOUTH);

I want to be able to control the sizing of the whole window, with a minimum and maximum size.

I thought I could have the 'centerPanel' JPanel as a BoxLayout, so I could have some control over it, but as it is, I can't control the sizing of the window at all.

I tried to make the 'mainPanel' use a BoxLayout, instead of a BorderLayout, but there where too many issues.

Is the main BorderLayout causing it to "ignore" the sizing? I know that the parts, other than the center, have some sizing control, that's why I tried to use a BoxLayout in the center.

Is it possible to keep the BorderLayout, and get it to work, with some other modifications, or would I need to switch to some other Layout Manager?

Thanks!

user1572522
  • 569
  • 2
  • 11
  • 26
  • I'm trying some more ways to do this.. – user1572522 Dec 26 '14 at 00:39
  • 1) See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) 2) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). – Andrew Thompson Dec 26 '14 at 01:01
  • 1
    *"I want to be able to control the sizing of the whole window, with a minimum and maximum size."* For minimum size, see [`Window.setMinimumSize(Dimension)`](https://docs.oracle.com/javase/8/docs/api/java/awt/Window.html#setMinimumSize-java.awt.Dimension-). I do not believe it is possible to enforce a maximum size without native code (unless of course, `setResizable(false)` is called..). – Andrew Thompson Dec 26 '14 at 01:04
  • Okay, thanks! I found an example that used a simple BorderLayout and a JFrame, and I no matter what I tried, I could keep sizing the window till it filled the whole screen. – user1572522 Dec 26 '14 at 16:52
  • Obviously you did not try calling `setResizable(false)`.. ;) – Andrew Thompson Dec 27 '14 at 02:51
  • Ideally, I'd like it so that the user could size the window up to the point where it reached the MaxSize, and stop, but like you said before, it probably can't be done without using native code. – user1572522 Dec 29 '14 at 00:38

0 Answers0