I have one JFrame open another JFrame, but when I try and click on the second JFrame when it pops up, nothing clicks. The thing is, if I select the old JFrame (click on it) and then select the new one, the new one will then work. The problem is I need it to work when it pops up because obviously I don't want users to have to click a hundred places to get the program to work.
Here is the code that calls/creates the new JFrame:
public void displayData(ArrayList<Judge> novice, ArrayList<Judge> advanced) {
DisplayWindow w = new DisplayWindow(novice, advanced);
w.setLocation(this.getLocation().x+20, this.getLocation().y+20);
w.setVisible(true);
w.setState(JFrame.NORMAL);
}
Here is the code for "DisplayWindow" (I suspect that the methods at the top have nothing to do with it because they don't manage the JFrame directly at all, but I still posted them):
public class DisplayWindow extends JFrame {
private JPanel contentPane;
private ArrayList<Judge> novice;
private ArrayList<Judge> advanced;
/**
* Create the frame.
*/
public static String getSingleText(ArrayList<Judge> d) {
StringBuilder product = new StringBuilder("");
for (Judge j : d) {
product.append(String.format("Judge: %s ", j.toString() + (j.getDebates().get(0).isAdvanced() ? 'A' : 'N')));
for (Debate de : j.getDebates()) {
product.append(String.format("Round: %s ", de != null ? de.toString() : "null"));
}
product.append("\n");
}
return product.toString();
}
public String getText(ArrayList<Judge> novice, ArrayList<Judge> advanced) {
StringBuilder product = new StringBuilder("");
product.append("Advanced:\n");
product.append(getSingleText(advanced));
product.append("\nNovice:\n");
product.append(getSingleText(novice));
return product.toString();
}
public DisplayWindow(ArrayList<Judge> novice, ArrayList<Judge> advanced) {
this.novice = novice;
this.advanced = advanced;
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JTextArea textArea = new JTextArea(getText(novice, advanced));
textArea.setEditable(false);
JScrollPane scroll = new JScrollPane(textArea);
contentPane.add(scroll, BorderLayout.CENTER);
JLabel lblNewLabel = new JLabel("Debate Calculation:");
contentPane.add(lblNewLabel, BorderLayout.NORTH);
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.SOUTH);
JButton btnSave = new JButton("Save");
panel.add(btnSave);
}
}
And, just in case, here is the code for how the old JFrame was created:
public DataWindow() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
setLocationRelativeTo(null);
String[] columnNames = {"School",
"Advanced #",
"Novice #",
};
Object[][] data = {
};
DefaultTableModel model = new DefaultTableModel(columnNames, 0);
table = new JTable(model){
public Class getColumnClass(int column) {
switch (column) {
case 0:
return String.class;
case 1:
return Integer.class;
case 2:
return Integer.class;
case 3:
return Integer.class;
default:
return Integer.class;
}
}
};
JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);
contentPane.add(scrollPane, BorderLayout.CENTER);
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.NORTH);
panel.setLayout(new WrapLayout(FlowLayout.CENTER, 5, 5));
chckbxCantJudgeOwn.setSelected(true);
panel.add(chckbxCantJudgeOwn);
chckbxCantDebateOwn.setSelected(true);
panel.add(chckbxCantDebateOwn);
chckbxCantJudgeSchool.setSelected(true);
panel.add(chckbxCantJudgeSchool);
chckbxCantDebateSchool.setSelected(true);
panel.add(chckbxCantDebateSchool);
chckbxCantDebateSchool.setSelected(true);
JPanel panel_1 = new JPanel();
contentPane.add(panel_1, BorderLayout.SOUTH);
panel_1.setLayout(new GridLayout(0, 2, 0, 0));
JButton btnNewButton = new JButton("+");
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.addRow(new Object[]{"?????", 0, 0});
}
});
panel_1.add(btnNewButton);
JButton button = new JButton("-");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int[] selectedRows = table.getSelectedRows();
if (selectedRows.length > 0) {
for (int i = selectedRows.length - 1; i >= 0; i--) {
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.removeRow(selectedRows[i]);
}
}
}
});
panel_1.add(button);
btnCancel.setEnabled(false);
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
processer.stop();
toggleButtons();
}
});
btnProcess.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
processer = new Thread(new Runnable() {
public void run() {
startProcess(getData(table));
}
});
processer.start();
toggleButtons();
}
});
panel_1.add(btnProcess);
panel_1.add(btnCancel);
}