View unanswered posts | View active topics It is currently Wed Apr 26, 2017 10:36 pm



Reply to topic  [ 3 posts ] 
 Enabling LC.hideMode() causes layout bug 
Author Message

Joined: Mon Aug 23, 2010 6:24 am
Posts: 54
Post Enabling LC.hideMode() causes layout bug
Hi,

Here is a runnable testcase demonstrating a bug in MigLayout 4.1:

Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import net.miginfocom.layout.CC;
import net.miginfocom.layout.LC;
import net.miginfocom.swing.MigLayout;

public class Testcase extends JPanel
{
   private static final long serialVersionUID = 1L;
   private final JToggleButton toggle = new JToggleButton("Toggle");
   private final JTree deviceTree;
   private final JLabel deviceNameHeader = new JLabel("Device Name");
   private final DefaultTreeModel deviceTreeModel;

   public Testcase()
   {
      super(new MigLayout());

      final DefaultMutableTreeNode deviceTreeRoot = new DefaultMutableTreeNode("Root");
      this.deviceTreeModel = new DefaultTreeModel(deviceTreeRoot);

      this.deviceTree = new JTree(deviceTreeModel);
      deviceTree.setOpaque(false);
      deviceTree.setVisibleRowCount(10);

      JScrollPane devicePane = new JScrollPane(deviceTree);
      add(devicePane, new CC().push().grow());

      JPanel tuningProperties = new JPanel(new MigLayout(new LC().hideMode(3)));
      tuningProperties.add(deviceNameHeader);

      add(tuningProperties, new CC().grow().wrap());

      tuningProperties.add(toggle);
      toggle.addActionListener(new ActionListener()
      {
         @Override
         public void actionPerformed(ActionEvent e)
         {
            if (toggle.isSelected())
               hideProperties();
            else
               showProperties();
         }
      });
   }

   /**
    * Updates the property panel.
    * <p/>
    * @param node the tree node to update
    */
   private void showProperties()
   {
      deviceNameHeader.setVisible(true);
      // Uncommenting the following line fixes the problem
      // revalidate();
   }

   /**
    * Invoked when the selected node has no properties.
    */
   private void hideProperties()
   {
      deviceNameHeader.setVisible(false);

      // Uncommenting the following line fixes the problem
      // revalidate();
   }

   public static void main(String[] args)
   {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.getContentPane().add(new Testcase());
      frame.setSize(800, 600);
      frame.setVisible(true);
   }
}


1. Run testcase
2. Initially you should see "Device Name [Toggle]" in the top right.
3. Click on "toggle".
4. Now you should see [Toggle] in the top right
5. Click on "toggle"
6. Now you should see "Device Name" followed by a thin line which is [Toggle] with incorrect layout
7. Click on "toggle". You should see step 4.
8. Click on "toggle". You should see step 2.
9. Click on "toggle". You should see [Toggle] in the top right, but it has excess spacing on the right.
10. Click on "toggle". You should see step 2. The pattern repeats forever from this point.

Expected behavior: Clicking [Toggle] should toggle between two repeatable states (step 2 and 4). Steps 6 and 9 seem to indicate layout bugs.
Workaround: Uncomment "revalidate()" in the testcase. For some reason this makes suppresses the problem.

Please let me know if you can reproduce this problem on your end.

Thanks,
Gili


Last edited by cowwoc on Sat Nov 26, 2011 2:29 am, edited 1 time in total.



Sat Nov 26, 2011 2:26 am
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Enabling LC.hideMode() causes layout bug
Thanks Gili,

It is put in the work queue. No guarantees on time though. Swamped. :)

Cheers,
Mikael


Sat Nov 26, 2011 2:28 am
Profile WWW
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Enabling LC.hideMode() causes layout bug
Hello,

Some kind of record for delay, I know..

This seem to be working on OS X and Windows 7 for the version I have now, which have a few bug fixes.

Cheers,
Mikael


Thu Feb 21, 2013 12:37 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.