[英]JOptionPane in Java
Does anyone know why tab (\\t) does not work with JOptionPane.showMessageDialog? 有谁知道为什么选项卡(\\ t)无法与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? 还有其他方法可以在JOptionPane中对齐文本吗?
Put your tabbed text into JTextArea 将选项卡式文本放入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. 再次查看您的数据,我可能会将其显示在JTable中,然后根据需要将其显示在JOptionPane或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. 如果需要更简单的方法,则将其显示在字体已设置为等距的JTextArea中,并使用String.format(...)或类似的方法将您的Strings显示在表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.