我花了一整天在网络上与本网站上寻找的答案,我的问题,希望你们能帮忙。首先,我想,当我选择“报告” JButton
显示一个ArrayList
到JTextArea
的内容。数组列表位于与文本区域分开的另一个类中。显示一个ArrayList <Object>在JTextArea中其他类
The method append(String) in the type JTextArea is not applicable
for the arguments (ArrayList.Account.TransactionObject>)
我可以显示数组列表只需在控制台窗口罚款,但我:我的问题与事实数组列表是对象的数组,所以,当我尝试以显示它我得到的错误茎当它在文本区域中显示时难倒了。我假设必须有某种问题将对象转换为字符串,因为我无法将其转换为字符串或使用数组列表调用toString
方法。这里是我的代码的相关部分.....
这是AccountUI
类哪里创建的JTextArea
的部分:
private JPanel get_ReportPane()
{
JPanel JP_reportPane = new JPanel(new BorderLayout());
Border blackline = BorderFactory.createLineBorder(Color.BLACK);
TitledBorder title = BorderFactory.createTitledBorder(blackline, "Transaction Report");
title.setTitleJustification(TitledBorder.CENTER);
JP_reportPane.setBorder(title);
/* Create 'labels' grid and JLabels */
JPanel report_labels = new JPanel(new GridLayout(2, 1, 5, 5));
report_labels.add(new JLabel("Current Account Balance: ", SwingConstants.RIGHT));
report_labels.add(new JLabel("Account Creation Date: ", SwingConstants.RIGHT));
JP_reportPane.add(report_labels, BorderLayout.WEST);
/* Create 'data' grid and text fields */
JPanel JP_data = new JPanel(new GridLayout(2, 1, 5, 5));
JP_data.add(TF_balance2 = new JTextField(10));
TF_balance2.setBackground(Color.WHITE);
TF_balance2.setEditable(false);
JP_data.add(TF_created = new JTextField(10));
TF_created.setBackground(Color.WHITE);
TF_created.setEditable(false);
JP_reportPane.add(JP_data, BorderLayout.CENTER);
/* Create 'buttons' grid and buttons */
JPanel JP_buttons = new JPanel(new GridLayout(2, 1, 5, 5));
JButton JB_report = new JButton("Report");
JB_report.setBackground(Color.GRAY);
JB_report.setMargin(new Insets(3, 3, 3, 3));
JB_report.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
reportAccount();
}
});
JP_buttons.add(JB_report);
JButton JB_close = new JButton("Close");
JB_close.setBackground(Color.GRAY);
JB_close.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
System.exit(0);
}
});
JP_buttons.add(JB_close);
JP_reportPane.add(JP_buttons, BorderLayout.EAST);
/* Create text area and scroll pane */
reportArea.setBorder(blackline);
reportArea.setForeground(Color.BLUE);
reportArea.setLineWrap(true);
reportArea.setWrapStyleWord(true);
JScrollPane scrollPane = new JScrollPane(reportArea);
reportArea.setEditable(false);
JP_reportPane.add(scrollPane, BorderLayout.SOUTH);
return JP_reportPane;
}
这是上面所示的方法(从JB_reportAction
监听器类称为),我尝试在文本区域(也AccountUI
类)来显示数组列表:
/**
* Method used to display account transaction history in the text field.
*/
protected void reportAccount()
{
reportArea.append(A.getTransactions());
}
而且这是在Account类,我能在一个反面来显示阵列内容的方法唯一的输出,但一直无法弄清楚如何数组内容传递给AccountUI
类作为字符串文本区域中显示:
public ArrayList<TransactionObject> getTransactions()
{
for (int i = 0; i < transactionList.size(); i++)
{
System.out.println(transactionList.get(i));
System.out.println("\n");
}
return transactionList;
}
我希望我已经澄清了我的问题,没有任何人混淆。任何有识之士将不胜感激。名单上
你重写了TransactionObject的toString()方法吗? –
您不能使用系统实用程序来绘制数据,使用绘图表面并在其中绘制对象。 –