generateClass
如何在字符串生成器中获取制表符\ n。 我希望像这样的客户类的arraylist的输出
public void search() {
String s1 = "",result="",
s2 = "";
s1 = JOptionPane.showInputDialog("Enter Account Number u want to find ", s2);
boolean found = false;
StringBuilder builder=new StringBuilder();
builder.append("Account Number\tName\t\tPincode\tUser Login\t\tBalance\t\tStatus\t\tType");
for (int i = 0; i < user.size(); i++) {
Customer_Data var = user.get(i);
if (var.accountNum == Integer.parseInt(s1))
{ builder.append("\n"+var.accountNum+"\t\t"+var.name+"\t\t"+var.pincode+"\t\t"+var.login+"\t\t"+var.startingBalance+"\t\t"+var.status+"\t\t"+var.type);
result=builder.toString();
//JOptionPane.showMessageDialog(null,result, "sad", JOptionPane.PLAIN_MESSAGE);
found = true;
}
}
if(found)
{
JOptionPane.showMessageDialog(null,builder, "sad", JOptionPane.PLAIN_MESSAGE);
}
if (!found) {
JOptionPane.showMessageDialog(null, "Not Fount");
}
}
但实际输出是
AccountID UserID Holders Name Type Balance Status
15 44045 xyz Savings 80,000 Active
18 43075 abc Savings 80,000 Active
答案 0 :(得分:0)
您必须进行一些更改才能使此工作生效。您应遵循的步骤如下:
JOptionPane#showMessageDialog()
方法中使用JLabel,这样您就可以在文本中添加标签。<html>
和 <pre>
标签在JLabel的文本开头。 (“ \ t”将被识别。)StringBuilder
。不要将所有文本附加到一行中。将其拆分为多个但更易读的行。一个简单的例子是:
StringBuilder sb = new StringBuilder();
sb.append("Hello");
sb.append(TAB);
sb.append("Stack");
sb.append(SPACE);
sb.append("Overflow");
JLabel label = new JLabel("<html><pre>" + sb.toString());
JOptionPane.showMessageDialog(null, label, "sad", JOptionPane.PLAIN_MESSAGE);
其中TAB和SPACE是:
private static final char TAB = '\t';
private static final char SPACE = ' ';
预览: