-1

I'm new to java, and here's a question I can't find the answer in Java doc and Google.

In my case, I want wanna restrict the height(just height) of a panel(which nested in a panel with BoxLayout), so I add codes like below:

p2.setMaximumSize(new Dimension(10000, 30));

It works fine until then.

The problem is that the numeric 10000 is some kid of ugly as you can see.

I want to know are there any constants to indicate a big enough number so I can replace the number 10000 with one of them. Or maybe are there any other better ways I can make it?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

2

Unless I'm missing something, you could use Integer.MAX_VALUE like so,

p2.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));

There are many possible solutions, another is to use the Screen Height, for example

GraphicsDevice gd = 
    GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int maxHeight = gd.getDisplayMode().getHeight();
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • 1
    Thank you Frisch. I want to know(or make sure), aren't there any constants specific to Swing or size? –  Jan 10 '14 at 17:07
  • Probably more realistic and safe would be Byte.MAX_VALUE. – Hovercraft Full Of Eels Jan 10 '14 at 17:11
  • @HovercraftFullOfEels ,I don't know why, but it seems Byte.MAX_VALUE does not work here. and, I wanna know why I should not ask this question here, so I can avoid next time. –  Jan 10 '14 at 17:22