我在使用带有RMI的表时遇到了一个很奇怪的问题。 客户端是一个时隙预订系统的实现,我已经将 实现为一个表。JTextField和RMI的GUI问题Java
我面临两个问题。 第一个在更改完成后导致表更新。 溶液似乎
private void cleanUp() {
panel.removeAll();
panel.setVisible(false);
panel.revalidate();
showTable();
}
这确实出现了工作。 (或者可能导致我的问题,我不知道)
我现在的问题是用方法 内的JTextField调用实际预订。
private JTextField txtClientname;
txtClientname = new JTextField();
txtClientname.setText("ClientName");
然后在确认按钮侦听 -
callBookingSlot(buttonAction, txtClientname.getText());
真正奇怪的是,这部作品最初一次。通过工作 我的意思是从JTextField中提取正确的值到表中。 第一次,它将把用户输入到该字段的值放入。 任何后续行为,它只会放在字符串“ClientName”
任何人有任何想法?这个问题似乎不是RMI相关的,我 尝试没有RMI,从文本字段仍然 行为采取同样的方式。 我知道我可能应该看fireTableUpdated等,我是,但它会是 伟大的,如果这是那些容易修复之一。
编辑 - 更多信息
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
public class StackOverFlowGUI {
private static JFrame frame;
private static JTable table;
private static JPanel panel;
private JTextField txtClientname;
private static JFrame bookingPopup = new JFrame();
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
StackOverFlowGUI window = new StackOverFlowGUI();
window.frame.setVisible(true);
}
});
}
public StackOverFlowGUI() {
initialize();
}
private void initialize() {
panel = new JPanel();
frame = new JFrame();
frame.setBounds(100, 100, 700, 751);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
panel.setBounds(10, 11, 674, 576);
frame.getContentPane().add(panel);
showTable();
}
private void showTable() {
table = new JTable();
panel.add(table);
panel.setVisible(true);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setCellSelectionEnabled(true);
showBookingPopup(2, 2);
}
private void showBookingPopup(int row, int col) {
bookingPopup.setBounds(100, 100, 220, 185);
bookingPopup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
bookingPopup.getContentPane().setLayout(null);
txtClientname = new JTextField();
txtClientname.setText("ClientName");
txtClientname.setBounds(10, 11, 184, 20);
bookingPopup.getContentPane().add(txtClientname);
txtClientname.setColumns(10);
bookingPopup.setVisible(true);
JPanel panel = new JPanel();
panel.setBounds(10, 65, 184, 33);
bookingPopup.getContentPane().add(panel);
JButton btnSubmit = new JButton("Submit");
btnSubmit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Here - works first time
System.out.println(txtClientname.getText());
//Continues to work if I don't call cleanUp - but then main window will not update
cleanUp();
}
});
btnSubmit.setBounds(10, 113, 89, 23);
bookingPopup.getContentPane().add(btnSubmit);
}
private void cleanUp() {
panel.removeAll();
panel.setVisible(false);
panel.revalidate();
showTable();
}
}
你应该看发布的SSCCE。 – camickr 2013-04-05 02:58:57
你能否提供显示问题的[SSCCE](http://sscce.org/)(最好没有RMI) – MadProgrammer 2013-04-05 02:59:00
我同意 - 我认为我们需要看到更多代码才能更好地理解发生了什么事情。我怀疑是线程问题,也可能是一个参考问题。 – 2013-04-05 02:59:27