How to create UI fields at runtime? [message #894321] |
Sun, 08 July 2012 03:03  |
Eclipse User |
|
|
|
I'm looking for help with how to build a dynamic UI with Scout. I understand that Scout provides a model which is used to render a GUI, but I'm struggling in using that model so I can perform typical UI tasks with it. I wrote a few lines of SWT code to show what I'd like to achieve. How do I do the same with Scout? The key points here are:
1.) I'd like to create text fields at runtime
2.) I'd like to do something when any key is pressed (not just when the _value_ of the field changes)
Any help is greatly appreciated!
Dirk
SWT example:
public class DynamicFieldsDemo {
private Display display;
private Shell shell;
private List<Text> textFields = new ArrayList<Text>();
private KeyListener keyListener = new KeyAdapter() {
@Override public void keyPressed(KeyEvent evt) {
for (Text field : textFields) {
boolean isActive = field == evt.getSource();
int bgColor = isActive ? SWT.COLOR_YELLOW : SWT.COLOR_GRAY;
field.setBackground(display.getSystemColor(bgColor));
if (!isActive) field.setText("");
}
}
};
DynamicFieldsDemo() {
display = new Display ();
shell = new Shell(display);
}
void open(int numberOfFields) {
int y = 10, x = 10;
// fields
for (int i = 0; i < numberOfFields; i++) {
Text field = new Text(shell, SWT.BORDER);
field.setLocation(x, y += 30); field.setSize(200, 25);
field.addKeyListener(keyListener);
textFields.add(field);
}
// open dialog
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
public static void main(String[] args) {
int numberOfFields = 5;
if (args.length == 1) {
numberOfFields = Integer.valueOf(args[0]);
}
new DynamicFieldsDemo().open(numberOfFields);
}
}
|
|
|
|
|
|
Re: How to create UI fields at runtime? [message #902441 is a reply to message #895181] |
Fri, 17 August 2012 11:11   |
Eclipse User |
|
|
|
I'm actually migrating a small app, I followed the Wiki's Notes but it keep to crash with a NPE at start.
Comparing my project with a test one created directly into 3.8, I found this difference in product's config.ini:
3.7:
osgi.bundles=org.eclipse.equinox.common@2:start,org.eclipse.update.configurator@3:start,org.eclipse.core.runtime@start
3.8:
osgi.bundles=org.eclipse.equinox.common@2\:start,org.eclipse.update.configurator@3\:start,org.eclipse.equinox.ds@3\:start,org.eclipse.core.runtime@start
When I updated it, my app started without errors! 
Now I have to solve only the lack of labels...
HTH
[Updated on: Fri, 17 August 2012 11:13] by Moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.63554 seconds