Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

resize external frame in "SingleFrameApplication"?

Thread view: 
TPG - 03 Mar 2008 16:21 GMT
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.
Jeff Higgins - 03 Mar 2008 18:36 GMT
> 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
[quoted text clipped - 14 lines]
>
> I'd appreciate being pointed in the right direction on this.

<Matisse - Swing>

<http://www.google.com/search?hl=en&q=jframe+minimum+size>
Jeff Higgins - 03 Mar 2008 18:43 GMT
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()

how about .setMinimumSize()
TPG - 03 Mar 2008 22:17 GMT
> I'd like to assure that the application can't be re-sized to
>
[quoted text clipped - 4 lines]
>
> how about .setMinimumSize()

I realize that my post did say "getMainFrame().setMaximumSize()", but
I actually did try "getMainFrame().setMaximumSize()".  It didn't work.
Mark Space - 03 Mar 2008 19:58 GMT
> 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.
Alex Kizub - 03 Mar 2008 20:44 GMT
> > 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
[quoted text clipped - 15 lines]
> 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.
Mark Space - 03 Mar 2008 20:51 GMT
> 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?
Mark Space - 03 Mar 2008 21:50 GMT
> 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.
Peter Duniho - 03 Mar 2008 22:26 GMT
> [...]  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
TPG - 05 Mar 2008 14:42 GMT
> 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
[quoted text clipped - 14 lines]
>
> 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.
Mark Space - 06 Mar 2008 21:56 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.