开发者

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 JOption开发者_如何学编程Pane?


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


Looking at your data again, I'd probably display it in a JTable, and then if desired, would display this in a JOptionPane or in a GUI. If you need simpler, then display it in a JTextArea whose font has been set to monospaced, and use String.format(...) or something similar to allow your Strings to be displayed in a table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜