JTable header not showing
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 |
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 |
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
299k17153266
299k17153266
asked Sep 28 '13 at 10:34
PhantomKidPhantomKid
57311
57311
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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 |
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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
MadProgrammerMadProgrammer
299k17153266
299k17153266
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 |
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 |
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 |
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
KundanKundan
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.
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