Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Short answer:</strong></p> <p>Use the StyledText instead of the Label - all things equal.</p> <p><img src="https://i.stack.imgur.com/AwaPU.png" alt="rightAlign"></p> <p><strong>Detailed answer:</strong></p> <p>There are a number of bugs (<a href="https://bugzilla.gnome.org/show_bug.cgi?id=120256" rel="nofollow noreferrer">120256</a> being a good entry point) in GTK about this "feature" most of them marked duplicate of each other, most of them harking back to gtk+ 2.4/2.6 some marked fixed. However, in 2011 gtk2+ version 2.22 (for Maverick Market), bugs seem to be remarkably resilient.</p> <p>Having read this bug report, I grepped the whole SWT source tree for the wordwrap keyword and it looks like Steve Northover boys have worked around the bug much better with the StyledText Control than with the Label Control.</p> <p>I reused Favonius test case (thx a lot Favonius ;-), and that apparently was good omen indeed.</p> <pre><code>import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class RightAlign2 { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); GridLayout layout = new GridLayout(); layout.numColumns = 2; shell.setLayout(layout); shell.setText("Alignment Test"); String[] labelTexts = new String[]{"label 1:","Another label:","Another label with wrapped text:"}; for (String labelText : labelTexts) { StyledText fieldText = new StyledText(shell, SWT.RIGHT |SWT.WRAP | SWT.BORDER ); fieldText.setText(labelText); GridData labelGridData = new GridData(GridData.HORIZONTAL_ALIGN_END); labelGridData.widthHint = 100; fieldText.setLayoutData(labelGridData); Text textField = new Text(shell, SWT.BORDER); GridData textGridData = new GridData(GridData.FILL_HORIZONTAL); textGridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; textGridData.widthHint = 248; textField.setLayoutData(textGridData); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload