View unanswered posts | View active topics It is currently Wed Mar 01, 2017 11:53 pm



Reply to topic  [ 3 posts ] 
 Inconstistent wrap (layout- vs. componentCC) behaviour 
Author Message

Joined: Wed Sep 21, 2011 1:41 pm
Posts: 16
Post Inconstistent wrap (layout- vs. componentCC) behaviour
Code:
/*
 * Created on 19.06.2012
 *
 */
package allIssues;

import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;

import net.miginfocom.swing.MigLayout;

/**
 * Implicit and explicit wrap aren't equivalent in some contexts.
 *
 * The three panels use the same grid (2 columns, 4 rows) with
 * the wrap defined in the layout constraint.
 * Task is to position
 * the label in the first cell of the last row.
 *
 * - layoutCCNewline: the only CC constraint is a newline on the label
 *   that's what I expected to work, but doesn't
 *   
 * - layoutCCWrapAndCCNewline: additionally add an explict CC wrap on the
 *   last button. That's working, but looks like a bug - the implicit
 *   wrap should have handled the positioning already
 *   
 * - layoutCCSkip: instead of a newline on the label, use a skip. this is
 *   working, but suboptimal (too much context knowledge)       
 *
 * @author Jeanette Winzenburg, Berlin
 */
public class WrapInconsistency {

    /**
     *
     * @return
     */
    private JComponent layoutCCNewline() {
        MigLayout layout = createLayout();

        JComponent content = new JPanel(layout);
        // add a 3 row spanning big growing component to first cell
        content.add(new JScrollPane(new JTable(20, 2)), "top, grow, spany 3");

        // add two buttons in the first two rows of the second column
        content.add(new JButton("One table command"), "sg button");
        content.add(new JButton("implicit wrap"), "sg button");

        // at this time, next free cell is (1, 2)
        // want in first of new line, that is (0, 3)
        content.add(new JLabel("wanna be on newline"), "newline");

        return content;
    }

    private JComponent layoutCCWrapCCNewline() {
        MigLayout layout = createLayout();

        JComponent content = new JPanel(layout);
        // add a 3 row spanning big growing component to first cell
        content.add(new JScrollPane(new JTable(20, 2)), "top, grow, spany 3");

        // add two buttons in the first two rows of the second column
        content.add(new JButton("One table command"), "sg button");
        content.add(new JButton("explicit wrap"), "sg button, wrap");
        content.add(new JLabel("wanna be on newline"), "newline");
        return content;
    }

    private JComponent layoutCCSkip() {
        MigLayout layout = createLayout();

        JComponent content = new JPanel(layout);
        // add a 3 row spanning big growing component to first cell
        content.add(new JScrollPane(new JTable(20, 2)), "top, grow, spany 3");

        // add two buttons in the first two rows of the second column
        content.add(new JButton("One table command"), "sg button");
        content.add(new JButton("implicit wrap"), "sg button");

        content.add(new JLabel("reached newline with skip"), "skip 2");

        return content;
    }

    /**
     * Creates and returns a 2 column/ 4 row grid with wrap 2
     *
     * @return
     */
    public MigLayout createLayout() {
        MigLayout layout = new MigLayout("wrap 2, debug", "[][]", // two columns
                // four rows, third growing
                "[][][fill, grow] []"

        );
        return layout;
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                WrapInconsistency wrapper = new WrapInconsistency();

                JFrame frame = new JFrame("");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new GridLayout(0, 3));
                frame.add(wrapper.layoutCCNewline());
                frame.add(wrapper.layoutCCWrapCCNewline());
                frame.add(wrapper.layoutCCSkip());
                frame.pack();
                frame.setLocationByPlatform(true);
                frame.setVisible(true);
            }
        });
    }

}


Cheers
Jeanette


Thu Jun 21, 2012 3:19 pm
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Inconstistent wrap (layout- vs. componentCC) behaviour
put in work queue.


Sat Jun 23, 2012 11:09 am
Profile WWW
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Inconstistent wrap (layout- vs. componentCC) behaviour
Hello,

I'm not sure this is a bug or even surprising.

newline will make sure it is on a new line, not necessarily the first column if that is occupied. If you do a wrap first to get to a new line and the say newline it will be on the next line, which is a free one.

Cheers,
Mikael


Fri Feb 22, 2013 3:39 pm
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.