Note that there are some explanatory texts on larger screens.

plurals
  1. POCard Layout refreshing/updating cards
    primarykey
    data
    text
    <p>I have a jFrame witch contains displayPanel and buttonPanel. In the button pannel, there are 2 buttons (button1, button2). When i press button1 - a new panel (card1) shows in the displayPanel. Card1 has a textfield and that writes the value to a database. When i press button2 - a new panel (card2) shows in the displayPanel. Card2 has a combobox that shows all those values from database.</p> <p>My problem - when i click on button1, submit my value, press button2 - combobox doesn't have that value shown yet. It only shows if i close my application and run it again.</p> <p>How do i make it so each time i press 'button2' (from buttonPanel in jFrame), values in combobox are refreshed?</p> <p>Here is the code from jFrame, that is responsible for showing cards:</p> <pre><code> private void button1ButtonActionPerformed(java.awt.event.ActionEvent evt) { CardLayout card = (CardLayout) displayPanel.getLayout(); card.show(displayPanel, "card1"); } private void button2ButtonActionPerformed(java.awt.event.ActionEvent evt) { CardLayout card = (CardLayout) displayPanel.getLayout(); card.show(displayPanel, "card2"); } </code></pre> <p>Here is the code that gets the values from database and puts them into combobox in card2:</p> <pre><code>public void fillComboBox(){ try { String sql = "SELECT * FROM Table1"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(sql); while (rs.next()){ String user_name= rs.getString("user_name"); pirmaspanelsvarbumoComboBox.addItem(user_name); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } </code></pre>
    singulars
    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.
 

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