Developer community
0 votes
375 views
asked by Guru (24.6k points) 29 51 79 | 375 views

2 Answers

0 votes
 
You can make use of the following code. To add JTable to JPanel.
 
JPanel panel = new JPanel();
this.setContentPane(panel);
panel.setLayout(null);
String data[][] = {{"1.", "ABC"}, {"2.", "DEF"}, {"3.", "GHI" }};
String col[] = {"Sr. No", "Name"};
JTable table = new JTable(data,col);
table.setBounds(100, 100, 100, 80);
panel.add(table);
setVisible(true);
setSize(300,300);

 

answered by Guru (27.1k points) 33 50 98
0 votes
JTable should be added into the JScrollPane which actually should be added into the JPanel.

The JPanel should have some layout manager.

If you don't care about the precision of components size you can use pure BorderLayout and combine it with FlowLayout and GridLayout. if you need precision - use jgoodies FormLayout.

The FormLayout is really tricky one, but you can play a little with WindowBuilder (which is embedded into Eclipse) and a look at the code it generates. It may look complicated but it is just an ignorance.
answered by Geek (15.3k points) 17 41 61

Related questions

0 votes
2 answers
asked by john Guru (27.1k points) 33 50 98 | 26 views
0 votes
1 answer
asked by john Guru (27.1k points) 33 50 98 | 77 views
+1 vote
1 answer
asked by john Guru (27.1k points) 33 50 98 | 20 views
0 votes
1 answer
asked by john Guru (27.1k points) 33 50 98 | 54 views
0 votes
1 answer
asked by sunny Expert (11.4k points) 14 23 29 | 1.2k views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users