GUI Designer and JTable = blank table ?

I am trying to learn to use the GUI builder. I have a simple test with a button and JTable in a JScrollPane on a form. However, I cannot get anything to show up inside the JTable. I have the simple main() below (irrelevant code removed for simplicity). No matter what I do I cannot get anything to show up in the table.

What's the trick to setting up a tablemodel so I can view the data in a jtable created from the GUI Designer??

public class TestGuiDesigner(){
public static void main(String[] args) {
//Create instance of main GUI test class
TestGuiDesigner testGui=new TestGuiDesigner();
FileModel fm=new FileModel("M:
Software");
//Setup a tablemodel with data for table
testGui.dataTable.setModel(fm);
testGui.dataTable.createDefaultColumnsFromModel();

JFrame frm=new JFrame("Testing GIU Designer");
frm.getContentPane().add(testGui.mainPanel);
frm.pack();

}

private JTable dataTable;
private JButton btnOK;
private JPanel mainPanel;
private JScrollPane jsp;

}

1 comment

WP wrote:

I am trying to learn to use the GUI builder. I have a simple test with a button and JTable in a JScrollPane on a form. However, I cannot get anything to show up inside the JTable. I have the simple main() below (irrelevant code removed for simplicity). No matter what I do I cannot get anything to show up in the table.

What's the trick to setting up a tablemodel so I can view the data in a jtable created from the GUI Designer??

public class TestGuiDesigner(){
public static void main(String[] args) {
//Create instance of main GUI test class
TestGuiDesigner testGui=new TestGuiDesigner();
FileModel fm=new FileModel("M:
Software");
//Setup a tablemodel with data for table
testGui.dataTable.setModel(fm);
testGui.dataTable.createDefaultColumnsFromModel();

JFrame frm=new JFrame("Testing GIU Designer");
frm.getContentPane().add(testGui.mainPanel);
frm.pack();

}

private JTable dataTable;
private JButton btnOK;
private JPanel mainPanel;
private JScrollPane jsp;

}


Try to run the following simple code. I suppose that you will get the
same result as you get in GUI builder. By default JTable constructed
with 0 row and 0 columns.

public static void main(String[] args) {
JFrame frame = new JFrame();
final JScrollPane jScrollPane = new JScrollPane(new JTable());
frame.setContentPane(jScrollPane);
frame.show();
}


--
Vladimir Kondratyev
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

Please sign in to leave a comment.