Search code examples
javajoptionpane

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?


Solution

  • 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));