Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Checkbox is not centering
Checkbox is not centering [message #447760] Fri, 17 December 2004 19:49
Phill Perryman is currently offline Phill PerrymanFriend
Messages: 214
Registered: July 2009
Senior Member
<br><font size=1 face="sans-serif">I am drawing a table like list (Variable height text so &nbsp;iam doing it myself).</font>
<br>
<br><font size=1 face="sans-serif">When I create a checkbox it does not appear in the center but over to the left.</font>
<br>
<br><font size=1 face="sans-serif">The code below is responsible for drawing the actual widget where the user answers the question, the first column is just a label with the question text.</font>
<br>
<br><font size=1 face="sans-serif">I create the butto for the checkbox as Button box = new Button(panel, SWT.CHECK | SWT.CENTER | SWT.BORDER);</font>
<br><font size=1 face="sans-serif">but it still appears left justified in its space.</font>
<br>
<br><font size=1 face="sans-serif">How can I get the chekbox in the middle of the widget size. </font>
<br>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; /**</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp;* Creates the Question Widget.</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp;* </font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp;* @param question Question that defines the type and content</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp;* @param x X position of the widget</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp;* @param y Y position of the widget</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp;* @param width The width of the widget</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp;* @param height The minimum height of the widget</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp;* @return The height that the Widget is actually set to</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp;*/</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; private int drawQuestionWidget(Question question, int x, int y, int width,</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int height) {</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Control control;</font>
<br>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; switch (question.getType()) {</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; case Question.HEADER:</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Label label = new Label(panel, SWT.CENTER | SWT.BORDER);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.setText(&quot;&quot;); //$NON-NLS-1$</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; control = label;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; case Question.DISPLAY:</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label = new Label(panel, SWT.CENTER | SWT.BORDER);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.setText(question.getDisplay());</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; control = label;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; case Question.INT:</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Text text = new Text(panel, SWT.CENTER | SWT.BORDER);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.setText(question.getDisplay());</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.addKeyListener(this);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.addVerifyListener(intVerifyListener);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.addFocusListener(this);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.setTextLimit(5);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; control = text;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; case Question.CHECKBOX:</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button box = new Button(panel, SWT.CHECK | SWT.CENTER | SWT.BORDER);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.setSelection(question.getQuantity() != 0);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.addSelectionListener(this);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; control = box;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; case Question.COMBO:</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Combo combo = new Combo(panel, SWT.DROP_DOWN | SWT.BORDER);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map map = question.getComboMap();</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Object[] display = map.values().toArray();</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Arrays.sort(display);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; display.length; i++)</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; combo.add((String) display[i]);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; combo.setText(question.getDisplay());</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; combo.addSelectionListener(this);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; control = combo;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; default:</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label = new Label(panel, SWT.CENTER | SWT.BORDER);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.setText(&quot;?&quot;); //$NON-NLS-1$</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; control = label;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; }</font>
<br>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; control.setLocation(x, y);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Point p1 = control.computeSize(width, SWT.DEFAULT, true);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; if (p1.y &gt; height)</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height = p1.y;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; if (height &lt; 21)</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height = 21;</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; control.setSize(width, height);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; if (question != null)</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; control.setData(question);</font>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; return height;</font>
<br>
<br><font size=1 face="sans-serif">&nbsp; &nbsp; }</font>
Previous Topic:SWT DoD Network Approval
Next Topic:How I can do click in a swt button by code?
Goto Forum:
  


Current Time: Fri Oct 23 03:35:18 GMT 2020

Powered by FUDForum. Page generated in 0.01303 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top