JTable header not showing
up vote
4
down vote
favorite
JTable header not showing...
My JTable header wont show even if add it into a container like JScrollPane...tell me why is it happen and how can i fix it or debug it.. I search through internet and all they saying is add container to your jtable, i did but still my header are not showing.
public void table(){
try{
rs = stat.executeQuery("SELECT * FROM payments;");
Vector<String> header = new Vector<String>();
header.add("PAYMENT");
header.add("AMOUNT");
header.add("MODIFIER");
header.add("DATE MODIFIED");
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while(rs.next()) {
Vector<Object> row = new Vector<Object>();
row.add(rs.getString("description"));
row.add(rs.getString("amount"));
row.add(rs.getString("remarks"));
row.add(rs.getString("date"));
data.add(row);
} // loop
table = new JTable(data, header);
JScrollPane scrollPane = new JScrollPane(table);
panel.add(table);
panel.add(table.getTableHeader());
//panel.removeAll();
//scroll.add(table);
validate();
}catch(Exception e){
System.out.println("Error in table: "+e);
}//try and catch
}
java database swing methods jtable
add a comment |
up vote
4
down vote
favorite
JTable header not showing...
My JTable header wont show even if add it into a container like JScrollPane...tell me why is it happen and how can i fix it or debug it.. I search through internet and all they saying is add container to your jtable, i did but still my header are not showing.
public void table(){
try{
rs = stat.executeQuery("SELECT * FROM payments;");
Vector<String> header = new Vector<String>();
header.add("PAYMENT");
header.add("AMOUNT");
header.add("MODIFIER");
header.add("DATE MODIFIED");
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while(rs.next()) {
Vector<Object> row = new Vector<Object>();
row.add(rs.getString("description"));
row.add(rs.getString("amount"));
row.add(rs.getString("remarks"));
row.add(rs.getString("date"));
data.add(row);
} // loop
table = new JTable(data, header);
JScrollPane scrollPane = new JScrollPane(table);
panel.add(table);
panel.add(table.getTableHeader());
//panel.removeAll();
//scroll.add(table);
validate();
}catch(Exception e){
System.out.println("Error in table: "+e);
}//try and catch
}
java database swing methods jtable
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
JTable header not showing...
My JTable header wont show even if add it into a container like JScrollPane...tell me why is it happen and how can i fix it or debug it.. I search through internet and all they saying is add container to your jtable, i did but still my header are not showing.
public void table(){
try{
rs = stat.executeQuery("SELECT * FROM payments;");
Vector<String> header = new Vector<String>();
header.add("PAYMENT");
header.add("AMOUNT");
header.add("MODIFIER");
header.add("DATE MODIFIED");
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while(rs.next()) {
Vector<Object> row = new Vector<Object>();
row.add(rs.getString("description"));
row.add(rs.getString("amount"));
row.add(rs.getString("remarks"));
row.add(rs.getString("date"));
data.add(row);
} // loop
table = new JTable(data, header);
JScrollPane scrollPane = new JScrollPane(table);
panel.add(table);
panel.add(table.getTableHeader());
//panel.removeAll();
//scroll.add(table);
validate();
}catch(Exception e){
System.out.println("Error in table: "+e);
}//try and catch
}
java database swing methods jtable
JTable header not showing...
My JTable header wont show even if add it into a container like JScrollPane...tell me why is it happen and how can i fix it or debug it.. I search through internet and all they saying is add container to your jtable, i did but still my header are not showing.
public void table(){
try{
rs = stat.executeQuery("SELECT * FROM payments;");
Vector<String> header = new Vector<String>();
header.add("PAYMENT");
header.add("AMOUNT");
header.add("MODIFIER");
header.add("DATE MODIFIED");
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while(rs.next()) {
Vector<Object> row = new Vector<Object>();
row.add(rs.getString("description"));
row.add(rs.getString("amount"));
row.add(rs.getString("remarks"));
row.add(rs.getString("date"));
data.add(row);
} // loop
table = new JTable(data, header);
JScrollPane scrollPane = new JScrollPane(table);
panel.add(table);
panel.add(table.getTableHeader());
//panel.removeAll();
//scroll.add(table);
validate();
}catch(Exception e){
System.out.println("Error in table: "+e);
}//try and catch
}
java database swing methods jtable
java database swing methods jtable
edited Sep 28 '13 at 10:43
MadProgrammer
297k17152263
297k17152263
asked Sep 28 '13 at 10:34
PhantomKid
57311
57311
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
10
down vote
accepted
Start by removing
panel.add(table.getTableHeader());
The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane
Also, change this...
panel.add(table);
To
panel.add(scrollPane);
when i do that (panel.add(scrollPane)) it shows me nothing..
– PhantomKid
Sep 28 '13 at 13:49
thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]
– PhantomKid
Sep 28 '13 at 13:54
1
Use an appropriate LayoutManager instead
– MadProgrammer
Sep 28 '13 at 19:59
add a comment |
up vote
3
down vote
Same problem I have face
You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
e.g.
JTable table = new JTable();
JScrollPane scrollPane= new JScrollPane(table);
frame.add(scrollPane);
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
accepted
Start by removing
panel.add(table.getTableHeader());
The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane
Also, change this...
panel.add(table);
To
panel.add(scrollPane);
when i do that (panel.add(scrollPane)) it shows me nothing..
– PhantomKid
Sep 28 '13 at 13:49
thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]
– PhantomKid
Sep 28 '13 at 13:54
1
Use an appropriate LayoutManager instead
– MadProgrammer
Sep 28 '13 at 19:59
add a comment |
up vote
10
down vote
accepted
Start by removing
panel.add(table.getTableHeader());
The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane
Also, change this...
panel.add(table);
To
panel.add(scrollPane);
when i do that (panel.add(scrollPane)) it shows me nothing..
– PhantomKid
Sep 28 '13 at 13:49
thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]
– PhantomKid
Sep 28 '13 at 13:54
1
Use an appropriate LayoutManager instead
– MadProgrammer
Sep 28 '13 at 19:59
add a comment |
up vote
10
down vote
accepted
up vote
10
down vote
accepted
Start by removing
panel.add(table.getTableHeader());
The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane
Also, change this...
panel.add(table);
To
panel.add(scrollPane);
Start by removing
panel.add(table.getTableHeader());
The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane
Also, change this...
panel.add(table);
To
panel.add(scrollPane);
answered Sep 28 '13 at 10:39
MadProgrammer
297k17152263
297k17152263
when i do that (panel.add(scrollPane)) it shows me nothing..
– PhantomKid
Sep 28 '13 at 13:49
thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]
– PhantomKid
Sep 28 '13 at 13:54
1
Use an appropriate LayoutManager instead
– MadProgrammer
Sep 28 '13 at 19:59
add a comment |
when i do that (panel.add(scrollPane)) it shows me nothing..
– PhantomKid
Sep 28 '13 at 13:49
thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]
– PhantomKid
Sep 28 '13 at 13:54
1
Use an appropriate LayoutManager instead
– MadProgrammer
Sep 28 '13 at 19:59
when i do that (panel.add(scrollPane)) it shows me nothing..
– PhantomKid
Sep 28 '13 at 13:49
when i do that (panel.add(scrollPane)) it shows me nothing..
– PhantomKid
Sep 28 '13 at 13:49
thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]
– PhantomKid
Sep 28 '13 at 13:54
thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]
– PhantomKid
Sep 28 '13 at 13:54
1
1
Use an appropriate LayoutManager instead
– MadProgrammer
Sep 28 '13 at 19:59
Use an appropriate LayoutManager instead
– MadProgrammer
Sep 28 '13 at 19:59
add a comment |
up vote
3
down vote
Same problem I have face
You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
e.g.
JTable table = new JTable();
JScrollPane scrollPane= new JScrollPane(table);
frame.add(scrollPane);
add a comment |
up vote
3
down vote
Same problem I have face
You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
e.g.
JTable table = new JTable();
JScrollPane scrollPane= new JScrollPane(table);
frame.add(scrollPane);
add a comment |
up vote
3
down vote
up vote
3
down vote
Same problem I have face
You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
e.g.
JTable table = new JTable();
JScrollPane scrollPane= new JScrollPane(table);
frame.add(scrollPane);
Same problem I have face
You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
e.g.
JTable table = new JTable();
JScrollPane scrollPane= new JScrollPane(table);
frame.add(scrollPane);
answered May 12 '14 at 5:44
Kundan
121210
121210
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19065970%2fjtable-header-not-showing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown