天天看點

java中的JOptionPane,Java中的JOptionPane

java中的JOptionPane,Java中的JOptionPane

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?

解決方案

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