GroupLayout - problem with baseline and multiline text comp

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

GroupLayout - problem with baseline and multiline text comp

Postby Rolf » Tue Jan 27, 2009 11:46 am

First, thanks to Instantiations for providing the GroupLayout for SWT. I'm trying to use it for manually coding my GUIs. I have a quite simple task: add a label left to a multiline text component which can resize in both directions. The label's baseline should be aligned with the text component's baseline of the first row. My Code:
Code: Select all
final Label label = new Label(composite, SWT.NONE);
label.setText("Comment:");

text = new Text(composite, SWT.WRAP
                           | SWT.MULTI
                           | SWT.BORDER
                           | SWT.H_SCROLL
                           | SWT.V_SCROLL);

final GroupLayout groupLayout = new GroupLayout(composite);
composite.setLayout(groupLayout);

groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup()
   .add(label)
   .addPreferredGap(LayoutStyle.RELATED)
   .add(text, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
);
groupLayout.setVerticalGroup(groupLayout.createParallelGroup(GroupLayout.BASELINE)
   .add(label)
   .add(text, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
);

Unfortunately, the text component does not resize vertically. If I replace the GroupLayout.BASELINE with GroupLayout.LEADING, the vertical resizing works, but the label is not aligned with the text component. What I'm doing wrong? Thanks in advance.

Rolf
Rolf
 
Posts: 5
Joined: Tue Jan 27, 2009 11:33 am

Re: GroupLayout - problem with baseline and multiline text comp

Postby Alexander.Mitin » Wed Jan 28, 2009 11:52 am

This is the expected behaviour. The size of group of baseline-aligned components calculated as prefAscent+prefDescent, see the source:
Code: Select all
// max(spring.getBaseline()) of all springs aligned along the baseline
// that have a baseline
private int prefAscent;
// max(spring.getPreferredSize().height - spring.getBaseline()) of all
// springs aligned along the baseline that have a baseline
private int prefDescent;

and
Code: Select all
if (allSpringsHaveBaseline) {
    return prefAscent + prefDescent;
}


And you set the height of the Text widget as default-preferred:
Code: Select all
.add(text, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
Alexander Mitin
Alexander.Mitin
Moderator
 
Posts: 155
Joined: Fri Jan 19, 2007 3:57 am

Re: GroupLayout - problem with baseline and multiline text comp

Postby Rolf » Thu Jan 29, 2009 5:19 am

Thanks for your answer, although I disagree. It is no expected behavior, because with Swing's GroupLayout everything works as expected:

Code: Select all
   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            final JLabel label = new JLabel("Comment");
            final JScrollPane scrollPane = new JScrollPane(new JTextArea());
            final JPanel panel = new JPanel();
            final GroupLayout groupLayout = new GroupLayout(panel);
            panel.setLayout(groupLayout);
            groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup()
                  .addComponent(label)
                  .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
            );
            groupLayout.setVerticalGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                  .addComponent(label)
                  .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
            );

            final JFrame frame = new JFrame();
            frame.setContentPane(panel);
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
         }
      });
   }


Rolf
Rolf
 
Posts: 5
Joined: Tue Jan 27, 2009 11:33 am

Re: GroupLayout - problem with baseline and multiline text comp

Postby Alexander.Mitin » Fri Jan 30, 2009 6:12 am

OK, you are right, this is fixed in most recent stable build.
Alexander Mitin
Alexander.Mitin
Moderator
 
Posts: 155
Joined: Fri Jan 19, 2007 3:57 am

Re: GroupLayout - problem with baseline and multiline text comp

Postby Rolf » Fri Jan 30, 2009 8:19 am

Thank you very much for fixing this issue so quick. That's how I call support!
Rolf
 
Posts: 5
Joined: Tue Jan 27, 2009 11:33 am

Re: GroupLayout - problem with baseline and multiline text comp

Postby Eric Clayberg » Tue Feb 03, 2009 5:10 am

Rolf wrote:Thank you very much for fixing this issue so quick. That's how I call support!

We try ;-)
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests