Java BorderLayout.add not working each time [duplicate]
This question already has an answer here:
Only one component shows up in JFrame
1 answer
I am creating a tabbed pane with tabs in the WEST or a borderlayout and the content in the middle. This is working great the first time the menu item is click setting the content in the pane I want. But once I have clicked a menu item once, that menu item with no longer repopulate the pane in the middle. Below is my set active function;
public void setActive()
panelShowLocation.setAllMenuItemsAsInActive();
active = true;
setBackground(color_panelHover);
menuText.setForeground(color_textHover);
panelShowLocation.add(content, BorderLayout.CENTER);
//content.setVisible(true);
panelShowLocation.revalidate();
java swing layout-manager border-layout
marked as duplicate by Andrew Thompson
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 2:12
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Only one component shows up in JFrame
1 answer
I am creating a tabbed pane with tabs in the WEST or a borderlayout and the content in the middle. This is working great the first time the menu item is click setting the content in the pane I want. But once I have clicked a menu item once, that menu item with no longer repopulate the pane in the middle. Below is my set active function;
public void setActive()
panelShowLocation.setAllMenuItemsAsInActive();
active = true;
setBackground(color_panelHover);
menuText.setForeground(color_textHover);
panelShowLocation.add(content, BorderLayout.CENTER);
//content.setVisible(true);
panelShowLocation.revalidate();
java swing layout-manager border-layout
marked as duplicate by Andrew Thompson
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 2:12
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Only one component shows up in JFrame
1 answer
I am creating a tabbed pane with tabs in the WEST or a borderlayout and the content in the middle. This is working great the first time the menu item is click setting the content in the pane I want. But once I have clicked a menu item once, that menu item with no longer repopulate the pane in the middle. Below is my set active function;
public void setActive()
panelShowLocation.setAllMenuItemsAsInActive();
active = true;
setBackground(color_panelHover);
menuText.setForeground(color_textHover);
panelShowLocation.add(content, BorderLayout.CENTER);
//content.setVisible(true);
panelShowLocation.revalidate();
java swing layout-manager border-layout
This question already has an answer here:
Only one component shows up in JFrame
1 answer
I am creating a tabbed pane with tabs in the WEST or a borderlayout and the content in the middle. This is working great the first time the menu item is click setting the content in the pane I want. But once I have clicked a menu item once, that menu item with no longer repopulate the pane in the middle. Below is my set active function;
public void setActive()
panelShowLocation.setAllMenuItemsAsInActive();
active = true;
setBackground(color_panelHover);
menuText.setForeground(color_textHover);
panelShowLocation.add(content, BorderLayout.CENTER);
//content.setVisible(true);
panelShowLocation.revalidate();
This question already has an answer here:
Only one component shows up in JFrame
1 answer
java swing layout-manager border-layout
java swing layout-manager border-layout
edited Nov 15 '18 at 2:08
Andrew Thompson
153k28162342
153k28162342
asked Nov 15 '18 at 1:21
Tom HansonTom Hanson
458316
458316
marked as duplicate by Andrew Thompson
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 2:12
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Andrew Thompson
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 2:12
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
panelShowLocation.add(content, BorderLayout.CENTER);
panelShowLocation.revalidate();
When you add a component to the panel the existing component is not removed.
Swing painting logic paints the last component added first. So the newly added component gets painted, but then the old components gets painted over top of the newly added component
So you need logic like:
panel.remove( theOldPanel );
panel.add(theNewPanel, BorderLayout.CENTER)
panel.revalidate();
panel.repaint();
The other option is to use a CardLayout. The CardLayout allows you to add multiple components to the same panel. Only one of the components is ever visible at the same time. Read the section from the Swing tutorial on How to Use CardLayout for more information and working examples.
Thank buddy. Got it to work based on your answer.
– Tom Hanson
Nov 15 '18 at 2:10
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
panelShowLocation.add(content, BorderLayout.CENTER);
panelShowLocation.revalidate();
When you add a component to the panel the existing component is not removed.
Swing painting logic paints the last component added first. So the newly added component gets painted, but then the old components gets painted over top of the newly added component
So you need logic like:
panel.remove( theOldPanel );
panel.add(theNewPanel, BorderLayout.CENTER)
panel.revalidate();
panel.repaint();
The other option is to use a CardLayout. The CardLayout allows you to add multiple components to the same panel. Only one of the components is ever visible at the same time. Read the section from the Swing tutorial on How to Use CardLayout for more information and working examples.
Thank buddy. Got it to work based on your answer.
– Tom Hanson
Nov 15 '18 at 2:10
add a comment |
panelShowLocation.add(content, BorderLayout.CENTER);
panelShowLocation.revalidate();
When you add a component to the panel the existing component is not removed.
Swing painting logic paints the last component added first. So the newly added component gets painted, but then the old components gets painted over top of the newly added component
So you need logic like:
panel.remove( theOldPanel );
panel.add(theNewPanel, BorderLayout.CENTER)
panel.revalidate();
panel.repaint();
The other option is to use a CardLayout. The CardLayout allows you to add multiple components to the same panel. Only one of the components is ever visible at the same time. Read the section from the Swing tutorial on How to Use CardLayout for more information and working examples.
Thank buddy. Got it to work based on your answer.
– Tom Hanson
Nov 15 '18 at 2:10
add a comment |
panelShowLocation.add(content, BorderLayout.CENTER);
panelShowLocation.revalidate();
When you add a component to the panel the existing component is not removed.
Swing painting logic paints the last component added first. So the newly added component gets painted, but then the old components gets painted over top of the newly added component
So you need logic like:
panel.remove( theOldPanel );
panel.add(theNewPanel, BorderLayout.CENTER)
panel.revalidate();
panel.repaint();
The other option is to use a CardLayout. The CardLayout allows you to add multiple components to the same panel. Only one of the components is ever visible at the same time. Read the section from the Swing tutorial on How to Use CardLayout for more information and working examples.
panelShowLocation.add(content, BorderLayout.CENTER);
panelShowLocation.revalidate();
When you add a component to the panel the existing component is not removed.
Swing painting logic paints the last component added first. So the newly added component gets painted, but then the old components gets painted over top of the newly added component
So you need logic like:
panel.remove( theOldPanel );
panel.add(theNewPanel, BorderLayout.CENTER)
panel.revalidate();
panel.repaint();
The other option is to use a CardLayout. The CardLayout allows you to add multiple components to the same panel. Only one of the components is ever visible at the same time. Read the section from the Swing tutorial on How to Use CardLayout for more information and working examples.
answered Nov 15 '18 at 2:04
camickrcamickr
275k15127239
275k15127239
Thank buddy. Got it to work based on your answer.
– Tom Hanson
Nov 15 '18 at 2:10
add a comment |
Thank buddy. Got it to work based on your answer.
– Tom Hanson
Nov 15 '18 at 2:10
Thank buddy. Got it to work based on your answer.
– Tom Hanson
Nov 15 '18 at 2:10
Thank buddy. Got it to work based on your answer.
– Tom Hanson
Nov 15 '18 at 2:10
add a comment |