resize external frame in "SingleFrameApplication"?

T

TPG

I'm in the process of building a "SingleFrameApplication" using
NetBeans IDE 6.0 and would like to be to control the size of the
external frame that is displayed when the application is run. For
example, I'd like to assure that the application can't be re-sized to
smaller than some minimum width x height. I can't figure out how to
accomplish this.

I've tried getMainFrame().setMaximumSize() from within the startup()
method within the project's generated SingleFrameApplication - but
that seems to have no effect when the application is run. In checking
this out, I have inserted code into the application that displays both
the current frame size and maximum frame size in response to a button
click. As I resize the running application by dragging its edges, the
maximum frame size stays at what it was set in the startup() method,
while the displayed actual frame size can vary well beyond that
maximum size.

I'd appreciate being pointed in the right direction on this.
 
J

Jeff Higgins

TPG said:
I'm in the process of building a "SingleFrameApplication" using
NetBeans IDE 6.0 and would like to be to control the size of the
external frame that is displayed when the application is run. For
example, I'd like to assure that the application can't be re-sized to
smaller than some minimum width x height. I can't figure out how to
accomplish this.

I've tried getMainFrame().setMaximumSize() from within the startup()
method within the project's generated SingleFrameApplication - but
that seems to have no effect when the application is run. In checking
this out, I have inserted code into the application that displays both
the current frame size and maximum frame size in response to a button
click. As I resize the running application by dragging its edges, the
maximum frame size stays at what it was set in the startup() method,
while the displayed actual frame size can vary well beyond that
maximum size.

I'd appreciate being pointed in the right direction on this.

<Matisse - Swing>

<http://www.google.com/search?hl=en&q=jframe+minimum+size>
 
J

Jeff Higgins

I'd like to assure that the application can't be re-sized to
how about .setMinimumSize()
 
M

Mark Space

TPG said:
I'm in the process of building a "SingleFrameApplication" using
NetBeans IDE 6.0 and would like to be to control the size of the
external frame that is displayed when the application is run. For

Sorry I can't find anything for you. This does feel like a hole in
Sun's API if there is no way to control the size of Windows.

(No pun intended, even though I'm running on Vista bloat-ware....)

The only thing I see is that Frames have a setResizable() method, which
can be set to false. This will at least give you some control over the
window size. I think SingleFrameApplication's are also Frames....

I don't even see a method or listener for receiving resize events. So
you can't really even tell if a Window has changed size. This has me
pretty bummed out. I think we should bug/enhancement-request this to Sun.


If anything turns up, please let us know. I'd like a point myself, for
future reference.
 
A

Alex Kizub

Sorry I can't find anything for you. This does feel like a hole in
Sun's API if there is no way to control the size of Windows.

(No pun intended, even though I'm running on Vista bloat-ware....)

The only thing I see is that Frames have a setResizable() method, which
can be set to false. This will at least give you some control over the
window size. I think SingleFrameApplication's are also Frames....

I don't even see a method or listener for receiving resize events. So
you can't really even tell if a Window has changed size. This has me
pretty bummed out. I think we should bug/enhancement-request this to Sun.

If anything turns up, please let us know. I'd like a point myself, for
future reference.

Once I got such "problem" and didn't find any API. So, I wrote own
simple BoundsChangedListener. In Java it's very simple.

However, since window itself is changed by OS you can control it only
via native interface. Or use BoundsChangedListener and stubbornly
change window bounds to something minimal at least.
Alex Kizub.
 
M

Mark Space

Alex said:
Once I got such "problem" and didn't find any API. So, I wrote own
simple BoundsChangedListener. In Java it's very simple.

Just FYI, Google "java BoundsChangedListener" returns no documents.
Maybe you meant something else?
 
M

Mark Space

Alex said:
However, since window itself is changed by OS you can control it only
via native interface. Or use BoundsChangedListener and stubbornly
change window bounds to something minimal at least.
Alex Kizub.

Poking around a bit more, I did find that Frame has an
addComponentListener method, which sends events to a ComponentListener
when the window is resized. The resize events do happen after the fact
though, so we're limited to reseting the window's size after the user
drags it, as you said. Not really ideal. I was hoping for some sort of
vetoable change listener.
 
T

TPG

I'd like to assure that the application can't be re-sized to


how about .setMinimumSize()

I realize that my post did say "getMainFrame().setMaximumSize()", but
I actually did try "getMainFrame().setMaximumSize()". It didn't work.
 
P

Peter Duniho

[...] As I resize the running application by dragging its edges, the
maximum frame size stays at what it was set in the startup() method,
while the displayed actual frame size can vary well beyond that
maximum size.

I'd appreciate being pointed in the right direction on this.

Unfortunately, the min and max sizes you can set for a component via
setMaximumSize() and setMinimumSize() are respected only when the size is
set via the API (e.g. calling setSize()). They are ignored when the
component is resized via user interaction.

Your only option is to add a ComponentListener to watch for resizing, and
then if the current (new) size of the component is outside the range
allowed by the maximum or minimum size, call setSize() with a new size
that is (typically you'd just pin the width and height to be within
whatever range you want to allow).

This mostly works, with the main issue that when you do this, the
component will flicker. This is annoying, but as far as I know it's the
best you can do. I did some Googling when I ran into this before and
found a number of user comments discussing the problem, including bug
reports on the Java run-time, but no solutions. I even posted here asking
if anyone had a better way, and got not a single reply.

I take that to mean that there really isn't anything better at the
moment. An unfortunate limitation in Java, but it's one I think most
people could live with.

Pete
 
T

TPG

I'm in the process of building a "SingleFrameApplication" using
NetBeans IDE 6.0 and would like to be to control the size of the
external frame that is displayed when the application is run.  For
example, I'd like to assure that the application can't be re-sized to
smaller than some minimum width x height.  I can't figure out how to
accomplish this.

I've tried getMainFrame().setMaximumSize() from within the startup()
method within the project's generated SingleFrameApplication  - but
that seems to have no effect when the application is run.  In checking
this out, I have inserted code into the application that displays both
the current frame size and maximum frame size in response to a button
click.  As Iresizethe running application by dragging its edges, the
maximum frame size stays at what it was set in the startup() method,
while the displayed actual frame size can vary well beyond that
maximum size.

I'd appreciate being pointed in the right direction on this.

Thanks for all the valiant efforts on my behalf by everyone who
responded. But those responses which suggested that the failure to
respect the max and min sizes in user resizings are a chracteristic of
the JFrame code itself appear to be in error - at least in terms of
the latest Java version. I had originally thought that the ignoring
of the JFrame's maximum and minimum sizes in my application had
something to do with my use of the "SingleFrameApplication" template
in NetBeans. After further expermentation, I now am convinced that
this is in fact the case.

To make a long story short, I have found that -

1. If you construct and display your own JFrame in the "traditional"
manner, it's manual resizing (with one exception) does respect any min
or max size restrictions you have set. There is no need to listen and
respond to resizing events. The one exception is that the max size is
ignored when a user "maximizes" the window. In this, a listener is
effective in resetting the JFrame to the indicated max size.

2. The problem I encountered can be traced to a specific anomoly in
NetBeans 6 that I can't explain. For some reason, the method
SingleFrameApplication.getMainFrame() does not return the frame
instance that it actually displays. So, one can set min and max sizes
on the mystery frame returned by that method without at all
restricting the actual frame that is displayed. Fortunately, however,
one can access the "real" frame via FrameView.getFrame() from the
FrameView subclass instance created by SingleFrameApplication.
Setting the max and min limits on the frame returned by that method
works exactly like any manually created JFrame as described above.
One must insure, however, that the SingleFrameApplication.show()
method has first been executed for the frame's FrameView instance
before invoking its getFrame() method.

I suspect that the dead frame that is accessed via the
SingleFrameApplication.getMainFrame() is a bug. I can see no reason
for creating this frame in addition to the one that is actually
displayed. Perhaps, an unintended duplication of frames arose when
they extended the Application Framework to SingleFrameApplications.

There are some real potential advantages to using the Java Apllication
Framework. It is a shame, however, that information of what it does
is so superficial. Even a simple word-sketch of what the various
constructors and methods are doing behind the scenes would have saved
me hours of pooking around.
 
M

Mark Space

TPG said:
To make a long story short, I have found that -

1. If you construct and display your own JFrame in the "traditional"
manner, it's manual resizing (with one exception) does respect any min
or max size restrictions you have set. There is no need to listen and

So, please let me understand. You are saying that you found no solution
to your issue, whether you use the SingleFrameApplication or a regular
JFrame?

That's what I suspected but I'd like to be sure. Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top