I have a problem with line breaks, I have made a code like this
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Welcome extends JFrame {
JMenu menuAdd, menuShow, menuEdit, menuHelp;
JMenuItem addCar, addRent, addUser, editCar, editCostumer, editUser, showCar, showRent, helpAbout;
JLabel lblWelcome;
JMenuBar mb;
public Welcome() {
setTitle("Car Tooner");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400,400);
setLocationRelativeTo(null);
setResizable(false);
menuAdd = new JMenu("Add");
menuShow = new JMenu("Show");
menuEdit = new JMenu("Edit");
menuHelp = new JMenu("Help");
addCar = new JMenuItem("Car");
addRent = new JMenuItem("Rent");
addUser = new JMenuItem("User");
editCar = new JMenuItem("Car");
editCostumer = new JMenuItem("Costumer");
editUser = new JMenuItem("User");
showCar = new JMenuItem("Car");
showRent = new JMenuItem("Rent");
helpAbout = new JMenuItem("About");
mb = new JMenuBar();
lblWelcome = new JLabel("Welcome, Admin \nto Car Tooner", SwingConstants.CENTER);
setJMenuBar(mb);
mb.add(menuAdd);
mb.add(menuEdit);
mb.add(menuShow);
mb.add(menuHelp);
menuAdd.add(addCar);
menuAdd.add(addRent);
menuAdd.add(addUser);
menuEdit.add(editCar);
menuEdit.add(editCostumer);
menuEdit.add(editUser);
menuShow.add(showCar);
menuShow.add(showRent);
menuHelp.add(helpAbout);
add(lblWelcome);
}
public static void main(String[] args) {
Welcome wlc = new Welcome();
wlc.setVisible(true);
}
}
but when I run the program, line break can not be executed,
lblWelcome = new JLabel("Welcome, Admin \nto Car Tooner", SwingConstants.CENTER);
i want to make text like this "Welcome, admin (\n new line) to Car Tooner" can anyone help me?