• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

JLabel

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the code where you're initializing the JLabels.
 
Nivedita Raj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I prefer to use swing 100%:

cheers
chantal
 
Nivedita Raj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic