resize external frame in "SingleFrameApplication"?

Discussion in 'Java' started by TPG, Mar 3, 2008.

  1. TPG

    TPG Guest

    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.
     
    TPG, Mar 3, 2008
    #1
    1. Advertising

  2. TPG

    Jeff Higgins Guest

    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>
     
    Jeff Higgins, Mar 3, 2008
    #2
    1. Advertising

  3. TPG

    Jeff Higgins Guest

    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()
     
    Jeff Higgins, Mar 3, 2008
    #3
  4. TPG

    Mark Space Guest

    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.
     
    Mark Space, Mar 3, 2008
    #4
  5. TPG

    Alex Kizub Guest

    On Mar 3, 2:58 pm, Mark Space <> 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.
     
    Alex Kizub, Mar 3, 2008
    #5
  6. TPG

    Mark Space Guest

    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?
     
    Mark Space, Mar 3, 2008
    #6
  7. TPG

    Mark Space Guest

    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.
     
    Mark Space, Mar 3, 2008
    #7
  8. TPG

    TPG Guest

    On Mar 3, 1:43 pm, "Jeff Higgins" <> 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.
     
    TPG, Mar 3, 2008
    #8
  9. TPG

    Peter Duniho Guest

    On Mon, 03 Mar 2008 08:21:08 -0800, TPG <> 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
     
    Peter Duniho, Mar 3, 2008
    #9
  10. TPG

    TPG Guest

    On Mar 3, 11:21 am, 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 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.
     
    TPG, Mar 5, 2008
    #10
  11. TPG

    Mark Space Guest

    TPG wrote:

    > 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.
     
    Mark Space, Mar 6, 2008
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin
    Replies:
    10
    Views:
    1,104
    Andrew Thompson
    Dec 12, 2003
  2. Replies:
    5
    Views:
    1,126
    Markus Weihs
    Apr 22, 2005
  3. wardemon

    Resize Frame

    wardemon, Nov 20, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    863
    wardemon
    Nov 21, 2006
  4. tobleron
    Replies:
    2
    Views:
    2,500
    tobleron
    Oct 7, 2008
  5. Replies:
    2
    Views:
    1,297
    Adrienne
    Feb 13, 2005
Loading...

Share This Page