Skip to main content

setExtendedState && setResizable bug?

9 replies [Last post]
odoremieux
Offline
Joined: 2004-03-30
Points: 0

Hello,

I am trying to maximised a Frame and make it not resizable.
In addNotify I am doing:
this.setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
setResizable(false);

This works on OSX 1.6, but not on Windows XP with java 1.6.0_17

It doesn't maximize the window, but make it non resizable.
If I comment out setResizable, then the window is maximized.

Is it a known bug?
Is there a workaround?

Thanks,

Olivier

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
odoremieux
Offline
Joined: 2004-03-30
Points: 0

Actually there are more issue related to that problem.

this.setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH); doesn't really maximized the window, so addWindowStateListener doesn't receive a windowStateChanged.
If I click on the maximize button, then it receive the event.

But here is the funny part. If I click on the maximize button, in the windowStateChanged, if I make the Frame non resizable, then if I click on minimize and then restore, the window take now the whole screen and hide the task bar. Before minimizing it didn't, and also the window is supposed to be non resizable.

All I want to do is to start a JFrame maximized and make it non resizable. How can I do that on windows?

Thanks in advance,

Olivier

anthony_p
Offline
Joined: 2006-07-24
Points: 0

> this.setExtendedState(this.getExtendedState() |
> JFrame.MAXIMIZED_BOTH); doesn't really maximized the
> window, so addWindowStateListener doesn't receive a
> windowStateChanged.
> If I click on the maximize button, then it receive
> the event.

That's right. The events get sent on user's actions only.

> But here is the funny part. If I click on the
> maximize button, in the windowStateChanged, if I make
> the Frame non resizable, then if I click on minimize
> and then restore, the window take now the whole
> screen and hide the task bar. Before minimizing it
> didn't, and also the window is supposed to be non
> resizable.

Weird. That looks like a bug. I think we could address it with a fix for 6916447.

> All I want to do is to start a JFrame maximized and
> make it non resizable. How can I do that on windows?

I guess there isn't a one-call solution for that. Off the top of my head I can suggest the following:

1. Using the GraphicsConfiguration.getBounds() and Toolkit.getScreenInsets() you can calculate the visible area of the screen.
2. Set your frame's bounds to that calculated location/size.
3. Make the frame non-resizable.
4. ...
5. PROFIT!

Apart from not being natively maximized, the frame should behave exactly as you want it to. Well, it will be movable though, but again, you could add a ComponentListener and return the window to the initial location whenever the user moves the frame. Although such behavior seems bad from usability point of view, if you need that - you could implement that. Hope this helps.

odoremieux
Offline
Joined: 2004-03-30
Points: 0

I found some workaround.

To prevent the Frame to take the whole size, hidding the toolbar, here is the trick on Windows:

addWindowStateListener(new WindowStateListener() {

@Override
public void windowStateChanged(WindowEvent e) {
if((e.getNewState() & Frame.ICONIFIED) == Frame.ICONIFIED){
setResizable(true);
}else if((e.getNewState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH){
setResizable(false);
}
}
});

To have the Window maximized , with the button with the right state:

pack();
setVisible(true);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);

It has to be done in this particular order.

I thought that :
GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()
Would give me the maximum available size, without the dock bar.

I have still some flickering issue, where the Frame seems to have some size and then get expanded.

Thanks,

Olivier

anthony_p
Offline
Joined: 2006-07-24
Points: 0

FYI: I've filed the following bug to track the issue:

http://bugs.sun.com/view_bug.do?bug_id=6916447

(it should become visible on the net in a day or two).

odoremieux
Offline
Joined: 2004-03-30
Points: 0

Thanks.

The workarpound is working for me.
The full scxreen mode is not really convinient for me, but maximized is.

Thanks again,

Olivier

anthony_p
Offline
Joined: 2006-07-24
Points: 0

You're welcome.

anthony_p
Offline
Joined: 2006-07-24
Points: 0

Hi,

First of, why do you ever need to use the addNotify() method? You most probably don't. Just set the desired properties right after creating your frame, and then just call the setVisible(true) method. Overriding/using the addNotify() method directly is not recommended due to its internal (relative to AWT) nature.

Regarding your issue, yes, I can reproduce the bug with 6u16 on WinXP. As a workaround you could dynamically change the resizability of the frame when it exits the maximized state (see the Window.addWindowStateListener()).

Or was your aim to disable leaving the maximized state for the frame? Could you clarify what you're trying to achieve?

--
best regards,
Anthony

odoremieux
Offline
Joined: 2004-03-30
Points: 0

Hi,

Thanks for the tips.

I just want to use all the screen without allowing people to resize the frame.

Thanks,

Olivier

anthony_p
Offline
Joined: 2006-07-24
Points: 0

Then perhaps what you really need is the full-screen window functionality? Check out the java.awt.GraphicsDevice.setFullScreenWindow(Window w).