Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Flowlayout in a vertical fashion

Thread view: 
sanmits@gmail.com - 07 Jul 2006 19:40 GMT
I am new to layout managers and I am not sure how to do this. I want to
have text paragraphs of various size shown in a vertical fashion in a
panel. I don't want to specify preferred size for the purpose of
internationalization though I have panel width and height specified
within which all the paragraphs should fit in.

I know I can use textarea but for flexibilty purpose (like having some
text underlined or different font,color) I tried using jlables with
html text for line wrapping and it works fine as long as I specify the
preferred size of the label such that height is set properly for
displaying multiple rows. Is there anyway I can do this without
specifying the height so that if text grows so does the height of
jlable automatically?

my code sample:

JPanel p1 = new JPanel(new FlowLayout());
ParentPanel.add(p1, Borderlayout.South); // panel added to south of
parent panel

//now add labels to p1
JLabel jLabel1 = new javax.swing.JLabel();
jLabel1.setFont(new java.awt.Font("Arial", 0, 12));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
jLabel1.setText("<html>Long Text.</html>");
//jLabel1.setPreferredSize(new java.awt.Dimension(250, 45)); //code i
want to avoid
p1.add(jLabel1);

JLabel jLabel2= new javax.swing.JLabel();
jLabel2.setFont(new java.awt.Font("Arial", 0, 12));
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
jLabel2.setText("<html>Another long text.</html>");
p1.add(jLabel2);

Any help is appreciated.

Thanks.
Andrew T. - 07 Jul 2006 20:25 GMT
> I am new to layout managers and I am not sure how to do this. I want to
> have text paragraphs of various size shown in a vertical fashion in a
> panel.
<big snip>

I suggest you put all your paragraphs in a single JEditorPane
in a JScrollPane in the JPanel for which you setPreferredSize().

As an aside, the GUI experts mostly read..
http://groups.google.com/group/comp.lang.java.gui

HTH

Andrew T.
Andrey Kuznetsov - 08 Jul 2006 01:05 GMT
> I know I can use textarea but for flexibilty purpose (like having some
> text underlined or different font,color) I tried using jlables with
[quoted text clipped - 3 lines]
> specifying the height so that if text grows so does the height of
> jlable automatically?

you should revalidate JLabel after text has changed.

Andrey

Signature

http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Bart Rider - 11 Jul 2006 09:18 GMT
>>I know I can use textarea but for flexibilty purpose (like having some
>>text underlined or different font,color) I tried using jlables with
[quoted text clipped - 7 lines]
>
> Andrey

Should not be neccessary. If changing a text in a JLabel, it
is automatically updated and repainted.

Bart
Andrey Kuznetsov - 12 Jul 2006 20:08 GMT
> Should not be neccessary. If changing a text in a JLabel, it
> is automatically updated and repainted.

but you must tell LayoutManager that something has changed.

Andrey

Signature

http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Bart Rider - 11 Jul 2006 09:22 GMT
> I know I can use textarea but for flexibilty purpose (like having some
> text underlined or different font,color) I tried using jlables with
[quoted text clipped - 8 lines]
>
> Thanks.

Don't forget to call pack() to tell the LayouyManager to layout
ALL components and subcomponents. Normally a JLabel shows
text of every length correctly, because it knows the
width and height of the text due to the font settings. But
as I said, you must give the chance to the label to call its
size to the layout manager, this is done by calling pack()
before setVisible( true ).

Bart


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.