Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: data won't show up in jtable

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default data won't show up in jtable

    Hello,

    I've got a problem with putting data into a JTable with a defaultTableModel from another class.

    Here is some example code

    i've got a actionPerformed in class A

    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==ok)
    {
    getDate();

    verlofTabel test = new verlofTabel();
    Object[] tempRow = new Object[]{"test1", "test2", "test 3", "test 4", "test5"};
    test.addRow(tempRow);
    this.setVisible(false);

    }
    }

    The Object[] tempRow has to update my DefaultTableModel in class B

    public class verlofTabel extends JPanel {

    private Object[][] databaseInfo;
    private JScrollPane pane;


    public Object[][] getDatabaseInfo() {
    return databaseInfo;
    }

    public void setDatabaseInfo(Object[][] databaseInfo) {
    this.databaseInfo = databaseInfo;
    }

    private String[] columns = {"Begin datum", "Eind datum", "Uren berekend", "Werkelijke uren", "Opmerkingen"};
    private MyTableModel dTable = new MyTableModel(databaseInfo, columns);

    public verlofTabel()
    {

    JTable tabelVerlof = new JTable(dTable);

    this.add(new JScrollPane(tabelVerlof));

    }

    public void addRow(Object[] row)
    {

    dTable.addRow(row);
    System.out.println("row added");

    }


    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,453
    My Mood
    Hungover
    Thanks
    144
    Thanked 638 Times in 546 Posts

    Default Re: data won't show up in jtable

    If you want help, you'll have to provide an SSCCE that demonstrates exactly what you're doing, in as few lines as possible. This should not be your whole program, but it should be enough for us to run it and see what's going on. Also, don't forget the highlight tags.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: data won't show up in jtable

    Quote Originally Posted by KevinWorkman View Post
    If you want help, you'll have to provide an SSCCE that demonstrates exactly what you're doing, in as few lines as possible. This should not be your whole program, but it should be enough for us to run it and see what's going on. Also, don't forget the highlight tags.
    I hope this will help.


    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.*;
     
     
    public class Medewerker extends JFrame implements ActionListener {
     
    	JPanel p1 = new JPanel();
        JButton verlof;
     
    	//Components JPanel2
     
    	verlofTabel p2 = new verlofTabel();
     
    	public Medewerker()
    	{
    		p2.setVisible(true);
    		initGui();
    		this.setLayout(new GridLayout(1,2));
    		this.getContentPane().add(p1);
    		this.getContentPane().add(p2);
    		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		this.pack();
    		this.setVisible(true);
     
     
    	}
     
     
    	public void initGui()
    	{
     
     
    		verlof = new JButton("Registreer verlof");
    		verlof.addActionListener(this);
    		p1.add(verlof);
     
     
    	}
     
     
     
    	public static void main(String[] args)
    	{
    		Medewerker test = new Medewerker();
    	}
     
     
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		if(e.getSource() == verlof)
    		{
    			ClassDateLayout dl = new ClassDateLayout();
    			dl.setVisible(true);
    			dl.pack();
     
     
     
     
    		}
     
    	}
     
     
    }

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
     
    import javax.swing.*;
     
     
     
     
    public class ClassDateLayout extends JDialog implements ActionListener{
     
     
    	JButton ok;
     
     
    	public ClassDateLayout()
    	{
    		initGui();
     
    		this.setVisible(true);
     
     
    	}
     
    	public void initGui()
    	{
     
     
     
    		ok = new JButton("Ok");
    		ok.addActionListener(this);
    		add(ok);
     
    	}
     
     
     
     
    	public void actionPerformed(ActionEvent e)
    	{
    		if(e.getSource()==ok)
    		{
     
     
    			Object[] tempRow = new Object[]{"test1", "test2", "test 3", "test 4", "test5"};
    			verlofTabel test = new verlofTabel();
    			test.addRow(tempRow);
    			this.setVisible(false);
     
    		}
    	}
     
     
    }

    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
     
     
    public class verlofTabel extends JPanel {
     
    	private Object[][] databaseInfo;
    	private JScrollPane pane;
     
    	public Object[][] getDatabaseInfo() {
    		return databaseInfo;
    	}
     
    	public void setDatabaseInfo(Object[][] databaseInfo) {
    		this.databaseInfo = databaseInfo;
    	}
     
    	private String[] columns = {"Begin datum", "Eind datum", "Uren berekend", "Werkelijke uren", "Opmerkingen"};
    	private MyTableModel dTable = new MyTableModel(databaseInfo, columns);
     
    	public verlofTabel()
    	{
     
    		JTable tabelVerlof = new JTable(dTable);
     
    		this.add(new JScrollPane(tabelVerlof));
     
    	}
     
    	public void addRow(Object[] row)
    	{
     
    		dTable.addRow(row);
    		System.out.println("row added");
     
    	}
     
     
    }
    [CODE]
    import javax.swing.table.DefaultTableModel;
     
     
    public class MyTableModel extends DefaultTableModel {
     
    	public MyTableModel(Object[][] data, String[] columnNames)
    	{
    		setDataVector(data, columnNames);
    	}
     
    	public boolean isCellEditable(int row, int column)
    	{
    		return false;
    	}
     
    }
    [/CODE]

  4. #4
    Junior Member Motion's Avatar
    Join Date
    Jul 2012
    Posts
    21
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: data won't show up in jtable

    You must use Vectors

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,038
    Thanks
    52
    Thanked 2,280 Times in 2,251 Posts

    Default Re: data won't show up in jtable

    Are you adding the data to the component that is visible in the GUI?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,334
    Thanks
    181
    Thanked 830 Times in 773 Posts
    Blog Entries
    5

    Default Re: data won't show up in jtable

    Quote Originally Posted by Motion View Post
    You must use Vectors
    Incorrect. And I'm not sure what - if any - bearing this has on data in the model not being visible in the view.

  7. #7
    Junior Member Motion's Avatar
    Join Date
    Jul 2012
    Posts
    21
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: data won't show up in jtable

    You must understand that coding is unique but one result is achieved at the end. DO NOT say incorrect for what u never tested.
    That's what i normally use genius...

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,334
    Thanks
    181
    Thanked 830 Times in 773 Posts
    Blog Entries
    5

    Default Re: data won't show up in jtable

    Quote Originally Posted by Motion View Post
    You must understand that coding is unique but one result is achieved at the end. DO NOT say incorrect for what u never tested.
    That's what i normally use genius...
    Your words: "you must use vectors." Read the API - this is incorrect because you can use arrays, and you could also use a List, or a Map, or a Set for that matter, presuming you extend the appropriate class and implement the appropriate methods.

  9. #9
    Junior Member Motion's Avatar
    Join Date
    Jul 2012
    Posts
    21
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: data won't show up in jtable

    Quote Originally Posted by copeg View Post
    Your words: "you must use vectors." Read the API - this is incorrect because you can use arrays, and you could also use a List, or a Map, or a Set for that matter, presuming you extend the appropriate class and implement the appropriate methods.
    Whatever... you are a moderator..huh? act like one!

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,038
    Thanks
    52
    Thanked 2,280 Times in 2,251 Posts

    Default Re: data won't show up in jtable

    Whatever... you are a moderator..huh? act like one!
    @Motion why the sassy backtalk?
    You mislead the OP by saying: You must use Vectors
    which isn't true. The API doc shows there are other choices. Besides, That is not the problem with the posted code.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,453
    My Mood
    Hungover
    Thanks
    144
    Thanked 638 Times in 546 Posts

    Default Re: data won't show up in jtable

    Quote Originally Posted by Motion View Post
    Whatever... you are a moderator..huh? act like one!
    This is a technical forum, not a kindergarten class. You were wrong, and copeg pointed that out so that anybody reading this forum doesn't get the wrong idea from you. It happens. Apologize, move passed it, and use it as a learning opportunity. Further bickering (and further posting of wrong advice as facts) will be cause for moderator action, so you'll get your wish.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. My bullseye won't show
    By JeremiahWalker in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 30th, 2012, 06:33 PM
  2. New to Java, Shape Won't Show in Console
    By BulgeBracket in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 30th, 2012, 06:30 PM
  3. JToggleButton's icon won't show up when pressed!
    By andreiutz10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 30th, 2011, 04:03 AM
  4. [SOLVED] Painted component won't show up
    By Fermen in forum Object Oriented Programming
    Replies: 2
    Last Post: June 19th, 2011, 04:24 PM