wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JLabel" Watch "JLabel" New topic
Author

JLabel

Nivedita Raj
Greenhorn

Joined: Oct 29, 2002
Posts: 3
Hi Friends,
This is regarding JLabel.
I have a Label with specified width & height.
It could occupy 9 characters in a line of 4 lines.
It displays fully.
Input
~~~~~
123456789
123456789
123456789
123456789
Output
~~~~~
123456789
123456789
123456789
123456789

But when i try to display 10 characters of 4 lines the display is such that specified in below the output
Input
~~~~~
1234567890
1234567890
1234567890
1234567890
Output
~~~~~
1234567890
1234567890
It displays only 2 lines & leaves a space between 2 lines.If the width is not sufficient the display should be suct that
4 lines displayed fully with last characters ie '0' cut but it displays as 2 lines with space between them.
The text is set as html content.
Culd pl.. help me out in this regard.why is it so?.Culd u pl.. explain.
ASAP.
Thanks & regards,
Nivedita
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
Please post the code where you're initializing the JLabels.
Nivedita Raj
Greenhorn

Joined: Oct 29, 2002
Posts: 3
Hi Chantal Ackermann,
Here I'm providing the code so that it wuld be useful for u to suggest me regarding this doubt.
import java.awt.*;
import javax.swing.*;
public class Frame1 extends JFrame {
private JLabel jLabel1;
JLabel jLabel2;
JLabel jlabel3;
public Frame1() {
try {
instanceCreation();
propertiesSet();

}
catch(Exception e) {
e.printStackTrace();
}
}
public void instanceCreation()
{
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jlabel3=new JLabel();
}
private void propertiesSet() throws Exception {
jLabel1.setBounds(new Rectangle(121, 86, 73, 75));
jLabel1.setPreferredSize(new Dimension(73,75));
jLabel1.setVerticalAlignment(javax.swing.SwingConstants.VERTICAL);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.HORIZONTAL);
jLabel2.setText("jLabel1");
jLabel2.setBounds(new Rectangle(1, 1, 73, 75));
jLabel2.setPreferredSize(new Dimension(73,75));
jLabel2.setVerticalAlignment(javax.swing.SwingConstants.VERTICAL);
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.HORIZONTAL);
jlabel3.setBounds(new Rectangle(200, 86, 80, 85));
jlabel3.setPreferredSize(new Dimension(80,85));
jlabel3.setVerticalAlignment(javax.swing.SwingConstants.VERTICAL);
jlabel3.setHorizontalAlignment(javax.swing.SwingConstants.HORIZONTAL);
java.awt.Font f=new java.awt.Font("Sansserif",Font.PLAIN,15);
jLabel1.setFont(f);
jLabel1.setForeground(new Color(0,35,3));
java.awt.Font f1=new java.awt.Font("Sansserif",Font.PLAIN,15);
jLabel2.setFont(f1);
jLabel2.setForeground(new Color(0,35,3));
jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.blue,3));
jLabel2.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.red,3));
jlabel3.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.cyan,3));
jLabel1.setText("<html>1234567890 1234567890 1234567890 1234567890</html>");
jLabel2.setText("<html>123456789 123456789 123456789 123456789</html>");
jlabel3.setText("<html>1234567890 1234567890 1234567890 1234567890</html>");
this.getContentPane().setLayout(null);
this.getContentPane().add(jlabel3,null);
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jLabel2, null);
}
public static void main(String args[])
{
Frame1 fr=new Frame1();
fr.setSize(300,300);
fr.setVisible(true);
}
}
Awaiting for u'r reply.
Thanks & Regards,
Nivedita.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi,
I prefer to use swing 100%:

cheers
chantal
Nivedita Raj
Greenhorn

Joined: Oct 29, 2002
Posts: 3
Hi Chantal,
U'r solution works very "fine".Thanks a lot.I like to add one more point.Its not such that the input is

it can be of any other characters other than these numbers as 1234567890.No of characters should be 10 in each line.Just for easy identification of no.of characters i have given as 1234567890.
My pbm is if the input for JLabel is given like this,ie1234567890
1234567890
1234567890
1234567890
"<html><body>1234567890<br>1234567890<br>1234567890<br>1234567890</body></html>"
in this case it behaves like that.
Initially I have 2 labels with text all 10 characters set fully,like given below:
1234567890
1234567890
1234567890
1234567890
Then if pair matches i set the border for it with width of 3.So in that case it behaves so.(as i said it comes only 2 lines with space in between them)& the output is such that
1234567890
1234567890
So culd u pl.. explain me in detail whats wrong in my case.I need a solution for it.
Thanks for immediate reply.Excepting the same now also according to my requirement.
Thanks & regards,
Nivedita.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JLabel
 
Similar Threads
Regular expression to check for specific special characters (any repitition) and 0 to 9 numbers
Regex for a combination of digits and space
FontMetrics
complicated assignment
html table style