Java BorderLayout.add not working each time [duplicate]










1
















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();










share|improve this question















marked as duplicate by Andrew Thompson java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

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.






















    1
















    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();










    share|improve this question















    marked as duplicate by Andrew Thompson java
    Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

    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.




















      1












      1








      1









      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();










      share|improve this question

















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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 java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      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 java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      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.
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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.






          share|improve this answer























          • Thank buddy. Got it to work based on your answer.

            – Tom Hanson
            Nov 15 '18 at 2:10

















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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.






          share|improve this answer























          • Thank buddy. Got it to work based on your answer.

            – Tom Hanson
            Nov 15 '18 at 2:10















          1














          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.






          share|improve this answer























          • Thank buddy. Got it to work based on your answer.

            – Tom Hanson
            Nov 15 '18 at 2:10













          1












          1








          1







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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





          Popular posts from this blog

          27

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          Category:Rhetoric