Question

In my

public UI(){

I have JTextField,JButtons and labels
I have also setLayout(null);

}

Now I'm Trying to create a JTable

JTable table = new JTable(data, headers);

But it wont display until I take out setLayout

For all the buttons,text boxes and labels I have setBounds();

How can I display the JTable while the setLayout is Null?

Was it helpful?

Solution

Don't use null Layout, instead use LayoutManagers. Java created for you amazing layouts, you just have to use it, and let the layout do your job instead of hard working of calculating the position and size.

That's my answer, but if you insist of using it, just call setBounds(x,y,width,height) method for the JTable. But again, don't use absolute positioning(null Layout).

//....
JScrollPane scrol = new JScrollPane(table);
scrol.setBounds(table.getBounds());
//....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top