This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Tab character in JPanel string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Tab character in JPanel string" Watch "Tab character in JPanel string" New topic
Author

Tab character in JPanel string

Alan Drennan
Greenhorn

Joined: May 24, 2005
Posts: 1
If I include a tab charater in a JPanel's String parameter, it does not display.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class demo extends JApplet {
JPanel numBar = new JPanel(new FlowLayout(FlowLayout.LEADING));
...

public void init(){
JApplet myApp = new JApplet();
...
getContentPane().add(sumBar);
...
String str = "xxx" + '\t' + "zzz";
JLabel msg1 = new JLabel(str, JLabel.LEADING);
msg1.setOpaque(false);
msg1.setForeground(fg);
numBar.setBackground(bg);
numBar.add(msg1);

}
}

The JLabel displays "xxxzzz", instead of "xxx zzz"

What am I doing wrong?
Fahd Shariff
Ranch Hand

Joined: Nov 22, 2002
Posts: 38
Yes JLabel does not render tab characters properly. You will need to override the paint method of JLabel to handle this. Or the second option is to replace your \t characters with spaces.


Fahd Shariff<br />"Let the code do the talking"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tab character in JPanel string
 
Similar Threads
How to use getModel() with JTabbedPane ?
Reg:Applet to servlet Communication
Reg : getting Values from applet using jsp
help~!
KeyListener failing for Macs