Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem may be here:</p> <pre><code>class passDatatoTable { public void passData() { String str1, str2, str3, str4; for (int i = 0; i &lt;= 10; i++) { str1 = "Column 1 of row: " + i; str2 = "Column 2 of row: " + i; str3 = "Column 3 of row: " + i; str4 = "Column 4 of row: " + i; gui SendStringsToGUI = new gui(str1, str2, str3, str4); // **** line (A) } } } </code></pre> <p>You seem to be creating a new gui object on <em>line (A)</em> and passing data into it. Please realize that this gui object has absolutely nothing to do with the gui object that is being displayed, and so passing data in this way will cause no observable change in the displayed data. </p> <p>A possible solution is to pass a reference to the gui object via a constructor parameter and then using public methods of that gui object (<em>not</em> a constructor) to set or change data.</p> <p>Here's a simple example of what I mean:</p> <pre><code>import java.awt.event.ActionEvent; import javax.swing.*; public class GuiTest2 { private static void createAndShowGui() { Gui2 mainPanel = new Gui2(); JFrame frame = new JFrame("Gui2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGui(); } }); } } class Gui2 extends JPanel { private JTextField field = new JTextField(10); // pass a reference to the GUI object into the controller via // its constructor private JButton nextBtn = new JButton(new NextController(this, "Next")); public Gui2() { field.setEditable(false); field.setFocusable(false); add(field); add(nextBtn); } public void setTextFieldText(String text) { field.setText(text); } } class NextController extends AbstractAction { private static final String[] TEXTS = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}; private Gui2 gui; private int index = 0; // pass the Gui2 object into the controller's constructor public NextController(Gui2 gui, String name) { super(name); this.gui = gui; // set the Gui2 field with the parameter } @Override public void actionPerformed(ActionEvent arg0) { // use the Gui2 object here gui.setTextFieldText(TEXTS[index]); index++; index %= TEXTS.length; } } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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