Results 1 to 4 of 4
  1. #1
    Fryslan is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Updating Data In JTable

    I have an int[] wich contains values that are changing all the time but when im putting them in an JTable, the value in the JTable doesnt change.
    does anyone know how i fix this?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Updating Data In JTable

    Does the model for that JTable know that its data is changing?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Fryslan is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Re: Updating Data In JTable

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.table.DefaultTableModel;
    
    import java.awt.Label;
    import javax.swing.JTable;
    
    
    public class TableTest extends JFrame {
    
    	private JPanel contentPane;
    	private JTable table;
    	private int[] TestValue;
    
    	/**
    	 * Launch the application.
    	 */
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					tabletest frame = new tabletest();
    					frame.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
    
    	/**
    	 * Create the frame.
    	 */
    	@SuppressWarnings("null")
    	public tabletest() {
    		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);
    		
    		table = new JTable();
    		table.setModel(new DefaultTableModel(
    			new Object[][] {
    				{"Test", TestValue[0]},
    				{"Test", TestValue[1]},
    				{"Test", TestValue[2]},
    			},
    			new String[] {
    				"New column", "New column", "New column"
    			}
    		));
    		contentPane.add(table, BorderLayout.CENTER);
    	}
    
    }

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Updating Data In JTable

    Updating elements in the TestValue array doesn't update your model and most certainly won't update the display of your JTable.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. JTable not updating with my AbstractTableModel
    By agarta in forum New To Java
    Replies: 5
    Last Post: 03-31-2013, 10:34 PM
  2. Replies: 3
    Last Post: 05-13-2011, 04:46 AM
  3. Updating JTable
    By dewitrydan in forum New To Java
    Replies: 3
    Last Post: 03-31-2011, 09:59 AM
  4. Updating the existing JTable !
    By Stephen Douglas in forum New To Java
    Replies: 2
    Last Post: 04-07-2010, 08:38 PM
  5. Problem with updating JTable
    By kwaspl in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 10:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •