Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks guys for helo. Finally i fix this problem. The big deal was to send a object to class that was filling data in table. In other words here is what I did:</p> <p>Remember class that was passing data to table? Well modify it like I did here:</p> <pre><code>public class passDatatoTable { passDatatoTable(ScanFrame gui){ String str1,str2,str3; 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; gui.model.setValueAt(str1, gui.i, 0); gui.model.setValueAt(str2, gui.i, 2); gui.model.setValueAt(str3, gui.i, 3); gui.i++; } }} </code></pre> <p>Now let's go back to gui class. Simply remove constructor (just rename it to anything you like and call that in main function). Here is example. NOTICE: All 2 constructor are gone because you don't need them.</p> <p>CODE:</p> <pre><code>public void CreateAndShowGUI(){ setVisible(true);//add this line to show gui JButton addData= new JButton("Add Data"); JButton next = new JButton("next"); JButton prev = new JButton("prev"); addData.addActionListener(this); next.addActionListener(this); prev.addActionListener(this); JPanel panel = new JPanel(new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.add(addData); buttonPanel.add(prev); buttonPanel.add(next); panel.add(buttonPanel, BorderLayout.SOUTH); panel.add(table.getTableHeader(), BorderLayout.PAGE_START); panel.add(scrollPane, BorderLayout.CENTER); getContentPane().add(panel); } </code></pre> <p>Now the important par is coming. Remmember button "Add Data"? Not all you need to do is to send refrence of this gui to class that fill data to table (passDatatoTable class) and it will work.</p> <pre><code>public void actionPerformed(ActionEvent e) { if ("Add Data".equals(e.getActionCommand())){ passDatatoTable passSomeData = new passDatatoTable(); passSomeData.passData(this);//here!! just add this and it will work!! } if ("next".equals(e.getActionCommand())) { Rectangle rect = scrollPane.getVisibleRect(); JScrollBar bar = scrollPane.getVerticalScrollBar(); int blockIncr = scrollPane.getViewport().getViewRect().height; bar.setValue(bar.getValue() + blockIncr); scrollPane.scrollRectToVisible(rect); } if ("prev".equals(e.getActionCommand())) { Rectangle rect = scrollPane.getVisibleRect(); JScrollBar bar = scrollPane.getVerticalScrollBar(); int blockIncr = scrollPane.getViewport().getViewRect().height; bar.setValue(bar.getValue() - blockIncr); scrollPane.scrollRectToVisible(rect); } } </code></pre> <p><strong>EDIT</strong></p> <pre><code>import javax.swing.*; public class Glavni { public static void main(String[] args) { // TODO Auto-generated method stub SwingUtilities.invokeLater(new Runnable() { public void run() { gui Scanner = new gui(); Scanner.CreateAndShowGUI(); } }); } } </code></pre> <p>Forgot to add main class. Here is it. If you have any problems/question please ask it. Thanks to @Hovercraft Full Of Eels and to @Reimeus for great help for their time. </p>
    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.
    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