Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FlowLayout contents not wrapping.

Status
Not open for further replies.

imp

Programmer
Jul 24, 2000
9
0
0
US
I'm having layout problems, which I'm hoping will be easy to answer.

I'm trying to make a row of smarticons in my Frame. I made an ImageButton class and created several instances of it that I added to a Panel that's set up with a FlowLayout. This by itself works great if I just add the Panel to my Frame (i.e. the icons appear one after the other, wrapping to create a second row of icons if the window is too narrow), but then the only thing in my frame is the row of icons. If I add the first Panel to another Panel that's set up with a BorderLayout, the Panel snaps to the top of the frame where I'd like it to be, but the icons cease to wrap, and if the window is too narrow, the icons that would appear past the right edge of the window just don't show up (i.e. BAD).

It seems like I'm attempting something quite common so I'm hoping this is a fairly well-known problem that someone on here could answer in their sleep.

Thanks in advance! [sig][/sig]
 
Their is a small hack to using layout managers. If you are out of all options and just do not want to use a layout manager you can do this....
in the panel class call
setLayout(null);
//this will allow me to add the elements i need without
//the constrictions of the layout mangers
//after trying pretty much all of them i decided upon this method

then you can do...
Buttons whatever = new Button();
whatever.setBounds(x,y,width,height);
//allows you to statically define the position for any element.....
In the book the said to only do this if you are completely out of options.... have you tried to make a custom Layout manager, might help ????

my full project....

later


ackka
tmoses@iname.com
"Do No Harm, Leave No Tracks"

ICMP Summer 2000, 2600 Article
 
I have NOT tried to create a custom Layout Manager yet. I think a Layout Manager would be the best approach, since otherwise I'll just end up having to do all that repositioning code in the "window resize" (?) event listener anyways, right? I guess maybe my question should be "How does one make a Layout Manager?". (I'm proficient in programming in general, but I'm still a newbie to Java, and still pretty fuzzy on OOP.) Any assistance will be appreciated. Thanks so far!
 
Layout managers like FlowLayout and BorderLayout are normally fine for quick solutions but when you want to do something slightly more complicated (and it only has to be slightly as you've found out) it can do things that you don't expect.

I normally opt for a GridBagLayout where you can specify detailed behaviour for each object you add. My Home -->
 
Hi,

I would also suggest to use a custom Layout Manager. I found two nice ones in the book "Graphic Java: Mastering the AWT" by David M. Geary. They are called "RowLayout" and "ColumnLayout".
I can send them to you by E-Mail if you like. My E-Mail is

tommy_hunziker@yahoo.de

Best regards Tom
 
How did you make the ImageButton class? I needed that functionality a while back and did it by subclassing awt.Canvas (which worked) but I was wondering if there was another way.

--Will Duty
wduty@radicalfringe.com

 
I subclassed Canvas as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top