Note that there are some explanatory texts on larger screens.

plurals
  1. POJComboBox stops responding when focus is directed to another component
    primarykey
    data
    text
    <p>I'm having an issue with a small personal application I am puttig together. I am loading data into a JDialog. Within the JDialog, I am loading multiple JPanels that each contain a TableLayout. I am dynamically generating the rows from the data that is loaded into the JDialog. Each row contains a JComboBox and a JTextField that are use to make comments about the status of that particular set of data.</p> <p>The problem I am encountering has to do with the JComboBox components that are being created. When the JDialog window opens, the JComboBox components are visable and working. Although, as soon as I direct the focus to a different type of component, the JComboBox components stop responding to the mouse clicks.</p> <p>There is no special logic around the JComboBox components. They simply populate with four different string values, which the user should be able to choose from. No ChangeListener is required for this.</p> <p>Also note, I wrap all the content in a ScrollPane within the JDialog.</p> <p>The following is the code where I create the JComboBox components within the TableLayout of the JPanel:</p> <pre><code> private JPanel createColumnPanel() { int columnCount = report.getColumns().size(); int rowCount = (columnCount * 2) - 1; SpringLayout layout = new SpringLayout(); JPanel padding = new JPanel(layout); TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Column Differences: "); border.setTitleJustification(TitledBorder.LEFT); double[] columns = new double[] {3, 75, 3, 175, 3, 150, 3, 100, 3, 125}; double[] rows = new double[rowCount]; for(int i = 0; i &lt; rowCount; i++) { rows[i] = 20; if (i + 1 &lt; rowCount) rows[i + 1] = 5; i++; } double size[][] = {columns, rows}; JPanel panel = new JPanel(new TableLayout(size)); columnStatus = new ArrayList&lt;JComboBox&lt;String&gt;&gt;(); for(int i = 0; i &lt; columnCount; i++) { JComboBox&lt;String&gt; comboBox = new JComboBox&lt;String&gt;(statusLiterals); comboBox.setEnabled(true); columnStatus.add(comboBox); } for (int i = 0; i &lt; columnCount; i++) { panel.add(new JLabel(report.getColumns().get(i).getSchema().toString()), 1 + ", " + (i * 2)); panel.add(new JLabel(report.getColumns().get(i).getTableName()), 3 + ", " + (i * 2)); panel.add(new JLabel(report.getColumns().get(i).getColumnName()), 5 + ", " + (i * 2)); panel.add(columnStatus.get(i), 7 + ", " + (i * 2)); panel.add(new JTextField(report.getColumns().get(i).getRequestor()), 9 + ", " + (i * 2)); } panel.setBorder(border); panel.setVisible(true); panel.setAlignmentX(LEFT_ALIGNMENT); panel.setBackground(Color.WHITE); layout.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, padding); layout.putConstraint(SpringLayout.SOUTH, padding, 10, SpringLayout.SOUTH, panel); layout.putConstraint(SpringLayout.EAST, padding, 10, SpringLayout.EAST, panel); layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, padding); padding.add(panel, SwingConstants.CENTER); padding.setBackground(Color.WHITE); return padding; } </code></pre> <p>The following is the full code for this particular JDialog:</p> <pre><code>public class ManageRequestsDialog extends JDialog { private static final long serialVersionUID = 1L; private ComparisonReport report; private JPanel outerPanel; private ScrollPane scrollPane; private JPanel innerPanel; private JPanel databasePanel; private JPanel tablePanel; private JPanel columnPanel; private List&lt;JLabel&gt; databaseSchemas = null; private List&lt;JComboBox&lt;String&gt;&gt; databaseStatus = null; private List&lt;JTextField&gt; databaseRequestors = null; private List&lt;JLabel&gt; tableSchemas = null; private List&lt;JLabel&gt; tableTableNames = null; private List&lt;JComboBox&lt;String&gt;&gt; tableStatus = null; private List&lt;JTextField&gt; tableRequestors = null; private List&lt;JLabel&gt; columnSchemas = null; private List&lt;JLabel&gt; columnTableNames = null; private List&lt;JLabel&gt; columnColumnNames = null; private List&lt;JComboBox&lt;String&gt;&gt; columnStatus = null; private List&lt;JTextField&gt; columnRequestors = null; private String[] statusLiterals = DifferenceStatus.getLiterals(); public ManageRequestsDialog (ComparisonReport report) { super(); this.report = report; outerPanel = createOuterPanel(); add(outerPanel); setLayout(new GridLayout(1, 1)); setModal(true); setSize(700, 500); setBackground(Color.WHITE); setResizable(false); setLocationRelativeTo(null); setVisible(true); } private JPanel createOuterPanel() { JPanel panel = new JPanel(new GridLayout(1, 1)); scrollPane = createScrollPane(); panel.add(scrollPane); panel.setVisible(true); panel.setBackground(Color.WHITE); return panel; } private ScrollPane createScrollPane() { ScrollPane scrollPane = new ScrollPane(); innerPanel = createInnerPanel(); scrollPane.add(innerPanel); scrollPane.setVisible(true); scrollPane.setBackground(Color.WHITE); return scrollPane; } private JPanel createInnerPanel() { JPanel panel = new JPanel(new BorderLayout()); if (report.getDatabases().size() &gt; 0) { databasePanel = createDatabasePanel(); panel.add(databasePanel, BorderLayout.NORTH); } if (report.getTables().size() &gt; 0) { tablePanel = createTablePanel(); panel.add(tablePanel, BorderLayout.CENTER); } if (report.getColumns().size() &gt; 0) { columnPanel = createColumnPanel(); panel.add(columnPanel, BorderLayout.SOUTH); } panel.setVisible(true); panel.setBackground(Color.WHITE); return panel; } private JPanel createDatabasePanel() { int databaseCount = report.getDatabases().size(); int rowCount = (databaseCount * 2) - 1; SpringLayout layout = new SpringLayout(); JPanel padding = new JPanel(layout); TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Database Differences: "); border.setTitleJustification(TitledBorder.LEFT); double[] columns = new double[] {3, 75, 3, 75, 3, 150}; double[] rows = new double[rowCount]; for(int i = 0; i &lt; rowCount; i++) { rows[i] = 20; if (i + 1 &lt; rowCount) rows[i + 1] = 5; i++; } double size[][] = {columns, rows}; JPanel panel = new JPanel(new TableLayout(size)); databaseStatus = new ArrayList&lt;JComboBox&lt;String&gt;&gt;(); for(int i = 0; i &lt; databaseCount; i++) { JComboBox&lt;String&gt; comboBox = new JComboBox&lt;String&gt;(statusLiterals); comboBox.setEnabled(true); databaseStatus.add(comboBox); } for (int i = 0; i &lt; databaseCount; i++) { panel.add(new JLabel(report.getDatabases().get(i).getSchema().toString()), 1 + ", " + (i * 2)); panel.add(databaseStatus.get(i), 3 + ", " + (i * 2)); panel.add(new JTextField(report.getDatabases().get(i).getRequestor()), 5 + ", " + (i * 2)); } panel.setBorder(border); panel.setVisible(true); panel.setAlignmentX(LEFT_ALIGNMENT); panel.setBackground(Color.WHITE); layout.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, padding); layout.putConstraint(SpringLayout.SOUTH, padding, 10, SpringLayout.SOUTH, panel); layout.putConstraint(SpringLayout.EAST, padding, 10, SpringLayout.EAST, panel); layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, padding); padding.add(panel, SwingConstants.CENTER); padding.setBackground(Color.WHITE); return padding; } private JPanel createTablePanel() { int tableCount = report.getTables().size(); int rowCount = (tableCount * 2) - 1; SpringLayout layout = new SpringLayout(); JPanel padding = new JPanel(layout); TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Table Differences: "); border.setTitleJustification(TitledBorder.LEFT); double[] columns = new double[] {3, 75, 3, 175, 3, 100, 3, 150}; double[] rows = new double[rowCount]; for(int i = 0; i &lt; rowCount; i++) { rows[i] = 20; if (i + 1 &lt; rowCount) rows[i + 1] = 5; i++; } double size[][] = {columns, rows}; JPanel panel = new JPanel(new TableLayout(size)); tableStatus = new ArrayList&lt;JComboBox&lt;String&gt;&gt;(); for(int i = 0; i &lt; tableCount; i++) { JComboBox&lt;String&gt; comboBox = new JComboBox&lt;String&gt;(statusLiterals); comboBox.setEnabled(true); tableStatus.add(comboBox); } for (int i = 0; i &lt; tableCount; i++) { panel.add(new JLabel(report.getTables().get(i).getSchema().toString()), 1 + ", " + (i * 2)); panel.add(new JLabel(report.getTables().get(i).getTableName()), 3 + ", " + (i * 2)); panel.add(tableStatus.get(i), 5 + ", " + (i * 2)); panel.add(new JTextField(report.getTables().get(i).getRequestor()), 7 + ", " + (i * 2)); } panel.setBorder(border); panel.setVisible(true); panel.setAlignmentX(LEFT_ALIGNMENT); panel.setBackground(Color.WHITE); layout.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, padding); layout.putConstraint(SpringLayout.SOUTH, padding, 10, SpringLayout.SOUTH, panel); layout.putConstraint(SpringLayout.EAST, padding, 10, SpringLayout.EAST, panel); layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, padding); padding.add(panel, SwingConstants.CENTER); padding.setBackground(Color.WHITE); return padding; } private JPanel createColumnPanel() { int columnCount = report.getColumns().size(); int rowCount = (columnCount * 2) - 1; SpringLayout layout = new SpringLayout(); JPanel padding = new JPanel(layout); TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Column Differences: "); border.setTitleJustification(TitledBorder.LEFT); double[] columns = new double[] {3, 75, 3, 175, 3, 150, 3, 100, 3, 125}; double[] rows = new double[rowCount]; for(int i = 0; i &lt; rowCount; i++) { rows[i] = 20; if (i + 1 &lt; rowCount) rows[i + 1] = 5; i++; } double size[][] = {columns, rows}; JPanel panel = new JPanel(new TableLayout(size)); columnStatus = new ArrayList&lt;JComboBox&lt;String&gt;&gt;(); for(int i = 0; i &lt; columnCount; i++) { JComboBox&lt;String&gt; comboBox = new JComboBox&lt;String&gt;(statusLiterals); comboBox.setEnabled(true); columnStatus.add(comboBox); } for (int i = 0; i &lt; columnCount; i++) { panel.add(new JLabel(report.getColumns().get(i).getSchema().toString()), 1 + ", " + (i * 2)); panel.add(new JLabel(report.getColumns().get(i).getTableName()), 3 + ", " + (i * 2)); panel.add(new JLabel(report.getColumns().get(i).getColumnName()), 5 + ", " + (i * 2)); panel.add(columnStatus.get(i), 7 + ", " + (i * 2)); panel.add(new JTextField(report.getColumns().get(i).getRequestor()), 9 + ", " + (i * 2)); } panel.setBorder(border); panel.setVisible(true); panel.setAlignmentX(LEFT_ALIGNMENT); panel.setBackground(Color.WHITE); layout.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, padding); layout.putConstraint(SpringLayout.SOUTH, padding, 10, SpringLayout.SOUTH, panel); layout.putConstraint(SpringLayout.EAST, padding, 10, SpringLayout.EAST, panel); layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, padding); padding.add(panel, SwingConstants.CENTER); padding.setBackground(Color.WHITE); return padding; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload