Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOptionPane in Java

Does anyone know why tab (\t) does not work with JOptionPane.showMessageDialog?

My code is as follows:

 String addText = "NAME\t\tADDRESS\t\tTEL.No\tEMAIL\n";
        for (int i = 0; i < addressBookSize; i++) {
           addText = addText+entry[i].viewAllInfo();
        }
        System.out.print(addText);
 JOptionPane.showMessageDialog(null, addText);

Are there other ways to align text in JOptionPane?

like image 649
newbie Avatar asked May 23 '26 00:05

newbie


1 Answers

Put your tabbed text into JTextArea

String addText = "NAME\t\tADDRESS\t\tTEL.No\tEMAIL\n";
        for (int i = 0; i < addressBookSize; i++) {
           addText = addText+entry[i].viewAllInfo();
        }
        System.out.print(addText);
 JOptionPane.showMessageDialog(null, new JTextArea(addText));
like image 131
Oleg Pavliv Avatar answered May 24 '26 14:05

Oleg Pavliv