Hi.
I'm having this problem of displaying a label on the frame. The Label is not fixed... ie depends on user input so can be any size.
When the size is big, the label get truncated and letters are replaced with dots.
There is a way to show all the label?
Thank you.
JLabel to large to be accommodated by JFrame
Page 1 of 15 Replies - 877 Views - Last Post: 20 April 2010 - 01:17 PM
Replies To: JLabel to large to be accommodated by JFrame
#2
Re: JLabel to large to be accommodated by JFrame
Posted 10 April 2010 - 09:19 AM
You could resize the frame to fit the label with the setSize(int w, int h) method to fit the size of the label. But I think it would be better to use a JTextArea, which holds many lines of text, rather than one long one. That way, you wouldn't have to worry about having the JFrame fill up the entire window as more text is entered
#3
Re: JLabel to large to be accommodated by JFrame
Posted 14 April 2010 - 12:18 AM
Thanks 4 reply.
Actually i like the idea of JTextArea.
Will need to do some line drawing as well in some latter stage. This is why i thought i use Label on the frame......but not sure how was going to do that either.
Line drawing will between the same letters of 2 different strings.
E.G:
HELLO JOHN
HI LIAM
Will need to draw lines between H/H and L/L.
I think is complicated as need to get coordinates for each letter......
Actually i like the idea of JTextArea.
Will need to do some line drawing as well in some latter stage. This is why i thought i use Label on the frame......but not sure how was going to do that either.
Line drawing will between the same letters of 2 different strings.
E.G:
HELLO JOHN
HI LIAM
Will need to draw lines between H/H and L/L.
I think is complicated as need to get coordinates for each letter......
#4
Re: JLabel to large to be accommodated by JFrame
Posted 17 April 2010 - 01:23 AM
Hi.
Found a "temporary" solution to the problem.
Here is the code:
I can "see" the slide bar and can read the label.
BUT if take away the comments, the slide bar disappear and I'm back to beginning....and I'll need to add more components to my JFrame.
Found a "temporary" solution to the problem.
Here is the code:
import java.awt.*;
import javax.swing.*;
public class v
{
public static void main(String args[])
{
JFrame frame = new JFrame("hello");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/*frame.setLayout(new FlowLayout());
JPanel north = new JPanel();
JLabel label8 = new JLabel("north label");
north.add(label8);
frame.add(north); */
JPanel center = new JPanel();
center.setLayout(new BoxLayout(center,BoxLayout.Y_AXIS));
JLabel label = new JLabel("This is the first label .............................");
center.add(label);
JLabel label1 = new JLabel("another label");
center.add(label1);
JScrollPane scrollPane = new JScrollPane(center);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(200, 150);
frame.setVisible(true);
}
}
I can "see" the slide bar and can read the label.
BUT if take away the comments, the slide bar disappear and I'm back to beginning....and I'll need to add more components to my JFrame.
This post has been edited by alti: 17 April 2010 - 01:26 AM
#5
Re: JLabel to large to be accommodated by JFrame
Posted 17 April 2010 - 01:53 AM
You can get the font metrics of the particular font you are using and then dynamically set the width/height of the JFrame using the metrics. For example, you can get the width of the string that you are wanting to draw and set the width of the window to the length of the string + a few pixels for spacing.
#6
Re: JLabel to large to be accommodated by JFrame
Posted 20 April 2010 - 01:17 PM
Hi.
Still working on this one....
Am I using the wrong approach here?
After some reading, looks like the paintComponent( Graphics g) method will do better using a string rather than have JPanel and JLabels?
What do you think?
Thanks in advance.
Still working on this one....
Am I using the wrong approach here?
After some reading, looks like the paintComponent( Graphics g) method will do better using a string rather than have JPanel and JLabels?
What do you think?
Thanks in advance.
This post has been edited by alti: 20 April 2010 - 01:19 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|