Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to insert a new line in a jlabel???

800425Sep 19 2007 — edited Sep 19 2007
hi everyone

i have a panel that have a jlabel... my problem is that i can make this label show line feeds even though im adding the "\n" escape character...

please help

thanks in advance

this is my code

<code>
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Test extends JFrame{

private String message = "This tool is used to set the database path\n" +
"If the database is on the local machine, you should use \"localhost\" or \"127.0.0.1\"\n" +
"If the database is on a networked machine, you should use the IP address of that machine\n";

private JLabel help = new JLabel(message);

private JPanel mPanel = new JPanel();
private JPanel hPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));

public Test() {
setTitle("Database Path Updater");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setSize(450,350);
setLocation(100,100);
setResizable(false);


setupComponents();
initializeGUI();
}

private void setupComponents() {
mPanel.setLayout(new BoxLayout(mPanel, BoxLayout.Y_AXIS));
}

private void initializeGUI() {
add(mPanel);

hPanel.add(help);

mPanel.add(hPanel);
}

public static void main(String[] args){
new Test().setVisible(true);
}

}
</code>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2007
Added on Sep 19 2007
4 comments
4,187 views