Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JList gets moved around in layout after data is added to it

17 views
Skip to first unread message

Brandon McCombs

unread,
Jul 24, 2005, 10:36:41 PM7/24/05
to
hello,

I have a JList in a panel next to(to the right) some textfields/buttons
in another panel. I'm using the gridbaglayout. When I'd add data to
the Jlist the Jlist would resize about 100 pixels I guess and would
squeeze the textfields/buttons in the adjacent panel into a smaller
area despite the fact that the data in the Jlist did not need that much
room (i had lots of whitespace at teh end of each entry in the Jlist).
I just switched to putting both of these panels into a tab within a
JtabbedPane and now when I add entries to the Jlist the Jlist gets
shifted down and off the viewable area of the Jframe while the other
panel (textfields/buttons) gets centered in the vieweable area. I
consider this worse than previously without the jtabbedpane since I
can't even see the Jlist contents w/o resizing the jframe window.
Without having to show any code (it might be hard to show it b/c my code
is getting more involved but i can try to post some if needed), does any
one know what the resizing of the Jlist and rearranging of it in my
layout can be caused by off hand? Is it due to the gridbaglayout and a
certain property of the constraints or something else possibly?

thanks


Pete Barrett

unread,
Jul 25, 2005, 2:10:50 PM7/25/05
to
On Mon, 25 Jul 2005 02:36:41 GMT, Brandon McCombs <bmcc...@ma.rr.com>
wrote:

>hello,
>
>I have a JList in a panel next to(to the right) some textfields/buttons
>in another panel. I'm using the gridbaglayout. When I'd add data to
>the Jlist the Jlist would resize about 100 pixels I guess and would
>squeeze the textfields/buttons in the adjacent panel into a smaller
>area despite the fact that the data in the Jlist did not need that much
>room (i had lots of whitespace at teh end of each entry in the Jlist).
>I just switched to putting both of these panels into a tab within a
>JtabbedPane and now when I add entries to the Jlist the Jlist gets
>shifted down and off the viewable area of the Jframe while the other
>panel (textfields/buttons) gets centered in the vieweable area.

I don't know offhand what the default layout manager for a JTabbedPane
is, but it sounds as if it might be FlowLayout, with the JList (now)
too big to fit on the same line as the other panel.


>I
>consider this worse than previously without the jtabbedpane since I
>can't even see the Jlist contents w/o resizing the jframe window.
>Without having to show any code (it might be hard to show it b/c my code
>is getting more involved but i can try to post some if needed), does any
>one know what the resizing of the Jlist and rearranging of it in my
>layout can be caused by off hand? Is it due to the gridbaglayout and a
>certain property of the constraints or something else possibly?
>

I don't know GridbagLayout well - I hate it like poison and never use
it. Have you tried BoxLayout? I tend to use JPanelS with BoxLayout
inside JPanelS with BoxLayout, or BorderLayout for some things, and if
those don't work, I write my own LayoutManager (which sounds more
difficult than it is).

Pete Barrett

Brandon McCombs

unread,
Jul 25, 2005, 6:58:13 PM7/25/05
to

Pete Barrett wrote:

> On Mon, 25 Jul 2005 02:36:41 GMT, Brandon McCombs <bmcc...@ma.rr.com>
> wrote:
>
> >hello,
> >
> >I have a JList in a panel next to(to the right) some textfields/buttons
> >in another panel. I'm using the gridbaglayout. When I'd add data to
> >the Jlist the Jlist would resize about 100 pixels I guess and would
> >squeeze the textfields/buttons in the adjacent panel into a smaller
> >area despite the fact that the data in the Jlist did not need that much
> >room (i had lots of whitespace at teh end of each entry in the Jlist).
> >I just switched to putting both of these panels into a tab within a
> >JtabbedPane and now when I add entries to the Jlist the Jlist gets
> >shifted down and off the viewable area of the Jframe while the other
> >panel (textfields/buttons) gets centered in the vieweable area.
>
> I don't know offhand what the default layout manager for a JTabbedPane
> is, but it sounds as if it might be FlowLayout, with the JList (now)
> too big to fit on the same line as the other panel.

But the thing is that the JList has no trouble at all fitting into the
JTabbedPane before data is added. And the data that is added to it is only
about 30 characters long and has plenty of room to fit into the JList but the
JList (before I used JTabbedPane) used to expand/resize to the left as I
mentioned previously and the data that would be listed would have a lot of
whitespace to the right of each entry. I tested to see if this whitespace
was actually part of the data by printing the data to the screen and adding
another character to the output and the character appeared right after my
real data so I knew there wasn't any hidden whitespace in my entry data. I
guess the problem of the layout position of the Jlist changing is due to the
size changing so the real problem is figuring out why the JList's size
changes in the first place, especially when it doesn't seem like to me that
it needs to.

>
> >I
> >consider this worse than previously without the jtabbedpane since I
> >can't even see the Jlist contents w/o resizing the jframe window.
> >Without having to show any code (it might be hard to show it b/c my code
> >is getting more involved but i can try to post some if needed), does any
> >one know what the resizing of the Jlist and rearranging of it in my
> >layout can be caused by off hand? Is it due to the gridbaglayout and a
> >certain property of the constraints or something else possibly?
> >
> I don't know GridbagLayout well - I hate it like poison and never use
> it. Have you tried BoxLayout? I tend to use JPanelS with BoxLayout

I tried boxlayout. I can't remember what happened when I used it but it
wasn't what I wanted. I may have ended up with lots of spacing around my text
labels (if I'm remembering correctly) still, which was what I was trying to
fix.

Brandon McCombs

unread,
Jul 25, 2005, 10:24:52 PM7/25/05
to

Pete Barrett wrote:

Just wanted to say I fixed the problem myself. It seems in my infinite
genius I had the JList added to 2 different JScrollPanes and not only that,
but I was adding the JList itself (and not even either one of the
scrollPanes) to the JPanel. I removed a scrollpane (obviously unneeded) and
modified the JPanel add method's argument to be the leftover scrollpane and
not the JList and now the JList doesn't shift in size.

thanks for your help Pete.


0 new messages