Resizing a JFrame at runtime

R

Rick

Hi,

I'm having trouble resizing a JFrame... okay, don't laugh.. I know this
is pathetic and I'm sure I'm missing out something here. Here's what I'm
trying to do:

I have a JFrame, that contains a JSplitPane. On the Left side of the
JSplitPane, I have a JPanel, on top of which I have two more panels, one
on BorderLayout.SOUTH and one on BorderLayout.NORTH.

On the Right side of the JSplitPane, I have another JPanel on which I'm
drawing something. Now the problem is that at runtime I need to "resize"
the Top panel (only it's Height) contained in the JSplitPane according
to some runtime measurments. I do that by using the setBounds() and
setSize() method (for some reason if I don't use both of these, it
doesn't work). In effect, the top panel get's resized and covers the
lower panel. So now I do the same with the lower panel, i.e., I resize
it by first 'setBound'ing it to start from (0, topPanel.getHeight). The
lower panel get's resized and is adjusted (I wonder if that's the
correct way of doing it because the underlyingpanel has a BorderLayout
and I was hoping the lower panel would "automagically" align itself but
that's not the case.. since I changed the bounds for the first panel, I
had to position the lower one myself).

The problem is that the JFrame itself does not change its size
automatically to accomodate the new JPanels. When I try doing this in
the paint() method or by writing my own method (something like
resetSize), it just doesn't work and it starts to flicker sometimes,
becomes extremely slow and even when it does resize, the portion of the
frame that resized is Grey and half of the JSplitpane is not visible.
It's just grey. I tried 'setBound'ing it, setSizing it.. everything! I'm
just going crazy over this and I'm sure there must be a cleaner, better
way to do what I'm trying to do. I just need to resize my JFrame and the
panels inside it according to some measurement I receive at runtime. Can
someone please help me out? Thanks!

Rick
 
H

Harald Hein

Rick said:
I'm having trouble resizing a JFrame... okay, don't laugh.. I know
this is pathetic and I'm sure I'm missing out something here.
Here's what I'm trying to do:

[Lots of words sniped]

Show us, no, show comp.lang.java.gui, REAL code. Short, working code
demonstrating the problem. It should be complete so people can compile
it without any changes and run it.
 
R

Rick

:( There are 10 classes where code is going in and going out.. I can't
create a repro because it'll be extremely difficult to extract code from
all of these classes and there's a lot happening... can someone just
tell me how to resize effectively? When should we use setSize,
setPreferredsize and setBounds? All three methods seem to work
differently and when should I use validate? Thanks

Rick

Harald said:
:

I'm having trouble resizing a JFrame... okay, don't laugh.. I know
this is pathetic and I'm sure I'm missing out something here.
Here's what I'm trying to do:


[Lots of words sniped]

Show us, no, show comp.lang.java.gui, REAL code. Short, working code
demonstrating the problem. It should be complete so people can compile
it without any changes and run it.
 

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

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top