Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] SWT Text widget disappears

The following simple SWT application replaces/adds a Text widget to a Group
when a menu item is pressed.

The Text widget appears in the Group fine originally... But, when the menu
button is pressed, the Text widget disappears. When you resize the window,
then the Text widget magically appears.

I'm not sure why the Text widget disappears. Here is the code:

Does anyone know how to make it so that the Text widget never disappears? It
would be a lot better user experience if the user did not have to resize the
text widget.


Thanks.

package com.software;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class GenerateSQL_SWT2 {

	private static Group mainParamsGroup;

	public static void main(String[] args) {
		try {
			final Display display = new Display();
			Shell mainShell = new Shell(display);
			mainShell.setLayout(new FormLayout());
			mainShell.setBounds(100, 100, 420, 320);
			mainShell.setText("Invisible Bug");
			Menu bar = new Menu(mainShell, SWT.BAR);
			mainShell.setMenuBar(bar);
			MenuItem fileMenu = new MenuItem(bar,SWT.CASCADE);
			fileMenu.setText("&File");
			Menu subMenu = new Menu(mainShell,SWT.DROP_DOWN);
			fileMenu.setMenu(subMenu);
			MenuItem configureMenuItem = new MenuItem(subMenu,SWT.NULL);
			configureMenuItem.setText("&Configure...");
			mainParamsGroup = new Group(mainShell, SWT.SHADOW_NONE);
			mainParamsGroup.setText("Parameters");
			GridLayout gridLayout = new GridLayout();
			gridLayout.numColumns = 1;
			mainParamsGroup.setLayout(gridLayout);
			FormData formData = new FormData();
			formData.top = new FormAttachment(0, 3);
			formData.left = new FormAttachment(0, 3);
			formData.right = new FormAttachment(100, -3);
			mainParamsGroup.setLayoutData(formData);
			addTextWidget("aaa"); // puts a text box with "aaa" in it
			configureMenuItem.addSelectionListener(new SelectionAdapter() {
				public void widgetDefaultSelected(SelectionEvent arg0) {
				}

				public void widgetSelected(SelectionEvent arg0) {
					addTextWidget("bbb"); // puts a text box with "bbb" in it
				}
			});
			
			mainShell.open();
			while (!mainShell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
			display.dispose();
		} catch (Exception e) { e.printStackTrace(); }
	}

	private static void addTextWidget(String sss) {
		org.eclipse.swt.widgets.Control children[] =
mainParamsGroup.getChildren();
		if (children != null) {
			for (int i = 0; i < children.length; i++) {
				children[i].dispose();
			}
		}
		Text t1 = new Text(mainParamsGroup,SWT.BORDER);
		t1.setText(sss);
	}
}
http://www.nabble.com/file/p13756178/invisible-bug.jpg 
-- 
View this message in context: http://www.nabble.com/SWT-Text-widget-disappears-tf4807900.html#a13756178
Sent from the Eclipse Platform - swt mailing list archive at Nabble.com.



Back to the top