View unanswered posts | View active topics It is currently Thu May 23, 2013 2:00 pm



Reply to topic  [ 2 posts ] 
 Invisible components not taking up space 
Author Message

Joined: Mon Aug 23, 2010 6:24 am
Posts: 54
Post Invisible components not taking up space
Hi,

It's my understanding that the default hidemode treats invisible components as if they were visible in terms of layout. Why, then, does the following testcase behave differently when "verticalFill1" is invisible?

Code:
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import net.miginfocom.layout.CC;
import net.miginfocom.layout.LC;
import net.miginfocom.swing.MigLayout;

public class Testcase extends JLayeredPane
{
   public Testcase()
   {
      setPreferredSize(new Dimension(800, 600));

      addComponentListener(new ComponentAdapter()
      {
         @Override
         public void componentResized(ComponentEvent e)
         {
            Dimension newSize = e.getComponent().getSize();
            for (int i = 0, size = getComponentCount(); i < size; ++i)
            {
               Component component = getComponent(i);
               component.setSize(newSize);
               if (component instanceof JComponent)
                  ((JComponent) component).revalidate();
            }
         }
      });
      JPanel consoleBarLayer = new JPanel(new MigLayout(new LC().debug(1000)));
      add(consoleBarLayer);

      JPanel verticalFill1 = new JPanel();
//      verticalFill1.setVisible(false);
      consoleBarLayer.add(verticalFill1, new CC().push().grow().wrap());

      JPanel consoleBar = new JPanel();
      consoleBar.setBackground(Color.RED);
      consoleBarLayer.add(consoleBar, new CC().grow());
   }

   public static void main(String[] args)
   {
      EventQueue.invokeLater(new Runnable()
      {
         @Override
         public void run()
         {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            JComponent mainPanel = new Testcase();
            frame.getContentPane().add(mainPanel);
            frame.pack();
            frame.setVisible(true);
         }
      });
   }
}


Thanks,
Gili


Sat May 21, 2011 5:40 pm
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Invisible components not taking up space
Are you sure that the component/panel reports the same min/preferred sizes when it's hidden and not? If not there's not much to do..


Sat May 21, 2011 6:14 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.