3

My application is currently too large for the window(monitor). I've built a scrollbar into the application to accommodate it but it still extends over the window rather than use the scrollbar. Originally, the initialization of the outer frame calls pack(), then setVisible(true).

I've tried to set the size of the frame but it doesn't seem to have an effect. The outer frame is a Masthead, and I call getWindow() on it to set size. Calling mframe.getWindow().setSize(640, 480); doesn't do anything.

This is the current behavior: enter image description here

This is what I'd like: enter image description here

EDIT: what's a good way for setting the app to full screen on startup?

kaid
  • 1,249
  • 2
  • 16
  • 32

2 Answers2

2

I've tried to set the size of the frame but it doesn't seem to have an effect.

That's because you called pack on the window. pack() sets the component's size to be the maximum of an components it contains, which makes your setSize() useless.

From the api:

pack() Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Rob Wagner
  • 4,391
  • 15
  • 24
  • i took pack() out before setSize(). I'm just saying it was there before. – kaid Jul 26 '12 at 22:24
  • 1
    Why would `pack` stop `setSize` from working in the future? Sorry if that's not what you meant, but that's how I read it. If you `setSize` then `pack`, yes your right, otherwise I'm confused... :P – MadProgrammer Jul 26 '12 at 23:04
  • i don't use pack at all anymore. But even if I try to chnage the dimensions of the frame, nothing seems to happen. I tried to setSize() and i tried to set it to fullsize: mframe.getWindow().setExtendedState(Frame.MAXIMIZED_BOTH); no effect. – kaid Jul 26 '12 at 23:17
1

Perhaps you want to use Toolkit#getScreenSize combined with setSize. Something like (for example, to set it to a specific percentage of screen size):

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
component.setSize((int)(screenSize.width * widthPercent),
                  (int)(screenSize.height * heightPercent));

If you want your app to start maximized, you might want to look at setExtendedState, like

myFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
Zach L
  • 16,072
  • 4
  • 38
  • 39