S
sanmits
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.
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.