Problem with label wrapping - preview does not match runtime

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

Problem with label wrapping - preview does not match runtime

Postby jan.tietze » Sun Jan 23, 2005 7:59 am

Hello,

I am trying to wrap text inside a label depending on the parent composite's width, and automatically re-align the position of subsequent UI elements. I'm using GridLayout to do this. In test/preview mode, everything looks fine, but at runtime, text is always displayed in a single row, and is not wrapped.

What am I doing wrong? How can my code achieve the same behavior the test/preview mode creates?

The following self-contained code fragment is an application reproducing the problem.

Kind Regards

Jan

Code: Select all
package de.cuc.test;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

/**
* Demonstration for label wrapping issue.
*
* This works as intended in SWT Designer Editor and Test/Preview mode - i.e.
* when the window is resized, the wrapping and layout changes to accomodate for
* the new widget sizes.
*
* However, when this is run as an application, text is displayed as a single
* line.
*
* How can I avoid this, and get the Test/Preview mode behavior for applications
* as well?

*/
public class ResizeLabelWrapTestGridLayout1 extends ApplicationWindow {

   public ResizeLabelWrapTestGridLayout1() {
      super(null);
      createActions();
      addToolBar(SWT.FLAT | SWT.WRAP);
      addMenuBar();
      addStatusLine();
   }

   protected Control createContents(Composite parent) {
      Composite container = new Composite(parent, SWT.NONE);
      container.setLayout(new GridLayout());

      final Composite composite = new Composite(container, SWT.NONE);
      composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      composite.setLayout(new GridLayout());

      final Label label = new Label(composite, SWT.NONE);
      label.setText("Headline");
      final Label label1 = new Label(composite, SWT.WRAP);
      label1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      label1
            .setText("This should be wrapped. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. Yadda yadda. ");

      final Composite composite_1 = new Composite(container, SWT.NONE);
      composite_1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      composite_1.setLayout(new GridLayout());

      final Label label2 = new Label(composite_1, SWT.WRAP);
      label2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      label2
            .setText("This should appear directly below the wrapped text and should automatically be re-aligned when the other label's height changes.");

      return container;
   }

   private void createActions() {
   }

   protected MenuManager createMenuManager() {
      MenuManager result = new MenuManager("menu");
      return result;
   }

   protected ToolBarManager createToolBarManager(int style) {
      ToolBarManager toolBarManager = new ToolBarManager(style);
      return toolBarManager;
   }

   protected StatusLineManager createStatusLineManager() {
      StatusLineManager statusLineManager = new StatusLineManager();
      statusLineManager.setMessage(null, "Test.");
      return statusLineManager;
   }

   public static void main(String args[]) {
      try {
         ResizeLabelWrapTestGridLayout1 window = new ResizeLabelWrapTestGridLayout1();
         window.setBlockOnOpen(true);
         window.open();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   protected void configureShell(Shell newShell) {
      super.configureShell(newShell);
      newShell.setText("Test");
   }

   protected Point getInitialSize() {
      return new Point(500, 375);
   }
}
jan.tietze
 
Posts: 6
Joined: Sun Jan 23, 2005 7:15 am
Location: Hamburg, Germany

Re: Problem with label wrapping - preview does not match run

Postby Eric Clayberg » Sun Jan 23, 2005 5:51 pm

jan.tietze wrote:I am trying to wrap text inside a label depending on the parent composite's width, and automatically re-align the position of subsequent UI elements. I'm using GridLayout to do this. In test/preview mode, everything looks fine, but at runtime, text is always displayed in a single row, and is not wrapped. What am I doing wrong? How can my code achieve the same behavior the test/preview mode creates?

Using your test case, I am seeing exactly the same behavior at runtime and in test/preview mode, so I'm not sure what to suggest.

You have the SWT.WRAP style assigned to the label, so it should wrap at runtime and in test/preview mode.
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

Postby jan.tietze » Mon Jan 24, 2005 12:22 am

Hello Eric,

I agree with you that it should wrap, but it doesn't do that for me at runtime. Here's what it looks like at design time:

Image

Test/preview time:

Image

Runtime:

Image

Windows XP SP2, details on the Eclipse build in question can be found here http://www.planet-pinguin.de/forums/instantiations/wrap-issue/System-Information.txt

I'll try this on my work laptop as well.

Any idea what might cause this? I couldn't find anything that would relate to this in the Eclipse Bugzilla.

Jan
jan.tietze
 
Posts: 6
Joined: Sun Jan 23, 2005 7:15 am
Location: Hamburg, Germany

Postby jan.tietze » Mon Jan 24, 2005 4:06 am

Same on my work laptop with an earlier (Version: 3.0.0
Build id: 200406251208) version of Eclipse & SWT, but the same version of SWT Designer 3.0.1.

I must say though that I have never had a Label wrap correctly with SWT on Win32 in my own code, except for when I explicitly set a width & height hint in the layout data of the label widget. It doesn't look as if this is known behavior though.
jan.tietze
 
Posts: 6
Joined: Sun Jan 23, 2005 7:15 am
Location: Hamburg, Germany

Postby jan.tietze » Mon Jan 24, 2005 4:39 am

Eric, from looking at https://bugs.eclipse.org/bugs/show_bug.cgi?id=9866, I guess you were using Eclipse 3.1 - correct?
jan.tietze
 
Posts: 6
Joined: Sun Jan 23, 2005 7:15 am
Location: Hamburg, Germany

Postby Eric Clayberg » Mon Jan 24, 2005 5:50 am

jan.tietze wrote:Eric, from looking at https://bugs.eclipse.org/bugs/show_bug.cgi?id=9866, I guess you were using Eclipse 3.1 - correct?

No. I'm using Eclipse 3.0.1 from 2004.09.16. Eclipse claims that the problem was fixed on 2004.08.31.
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

Postby jan.tietze » Mon Jan 24, 2005 6:32 am

That's the version I created the screenshots with btw... (3.0.1 M200409161125) :)

I thought bug#9866 said this was fixed for 3.1 builds only and checked with the build notes for SWT, and indeed in R-3.0.1-200409161125/buildnotes/buildnotes_swt.html it doesn't mention bug#9866, whereas in /S-3.1M2-200409240800/buildnotes/buildnotes_swt.html it says bug#9866 was fixed.

It seems to be a problem in SWT anyway, not in your code. I'll do some more testing.
jan.tietze
 
Posts: 6
Joined: Sun Jan 23, 2005 7:15 am
Location: Hamburg, Germany

Postby jan.tietze » Mon Jan 24, 2005 6:58 am

I have now tried Eclipse 3.1 Build id: 200412162000 (I suppose any build later than 2004.08.31 would have worked) and the wrapping now works here as well.

I consider this fixed now (seems to be bug#9866). I'd tend to think that you were using the SWT from 3.1 though then, are you sure it was 3.0.1? Did you change anything w/ regard to SWT libraries in your project, ie. is the project in which you ran the test case referencing a later version of SWT?

Anyway, I'll try to put this later SWT in my 3.0.1-based RCP app.
jan.tietze
 
Posts: 6
Joined: Sun Jan 23, 2005 7:15 am
Location: Hamburg, Germany


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest