Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > resize external frame in "SingleFrameApplication"?

Reply
Thread Tools

resize external frame in "SingleFrameApplication"?

 
 
TPG
Guest
Posts: n/a
 
      03-03-2008
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.
 
Reply With Quote
 
 
 
 
Jeff Higgins
Guest
Posts: n/a
 
      03-03-2008

TPG wrote:
> 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>


 
Reply With Quote
 
 
 
 
Jeff Higgins
Guest
Posts: n/a
 
      03-03-2008

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()


 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      03-03-2008
TPG wrote:
> 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.

 
Reply With Quote
 
Alex Kizub
Guest
Posts: n/a
 
      03-03-2008
On Mar 3, 2:58 pm, Mark Space <(E-Mail Removed)> wrote:
> TPG wrote:
> > 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.


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.
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      03-03-2008
Alex Kizub wrote:

> 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?
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      03-03-2008
Alex Kizub wrote:

> 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.
 
Reply With Quote
 
TPG
Guest
Posts: n/a
 
      03-03-2008
On Mar 3, 1:43*pm, "Jeff Higgins" <(E-Mail Removed)> wrote:
> 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()


I realize that my post did say "getMainFrame().setMaximumSize()", but
I actually did try "getMainFrame().setMaximumSize()". It didn't work.
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      03-03-2008
On Mon, 03 Mar 2008 08:21:08 -0800, TPG <(E-Mail Removed)> wrote:

> [...] 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
 
Reply With Quote
 
TPG
Guest
Posts: n/a
 
      03-05-2008
On Mar 3, 11:21*am, TPG <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get PAN newsreader to resize photos to fit in the body frame FJ Chaney Digital Photography 31 10-10-2007 12:56 AM
Resize Frame wardemon ASP .Net 2 11-21-2006 02:23 PM
How to prevent Tkinter frame resize? phil_nospam_schmidt@yahoo.com Python 5 04-22-2005 08:52 PM
How to resize all images sizes and coordinates of the images on resize browser rams.kakara@gmail.com ASP General 2 02-13-2005 09:03 AM
Please...Applet frame resize problem Kevin Java 10 12-12-2003 06:11 AM



Advertisments