Java SWT Update Text control -
i've written much java code since 1996, never tried swt. though i'd pick simple start with, became stuck quite on, several swt/jface/rcp books before me not help me problem.
i trying create command line application run in swt window. not need kind of input user, needs show sysout. application generates more 30 lines of sysout.
public class testgui implements runnable { private display display; private shell shell; private text text; public void run() { display = new display(); shell = new shell(display, swt.dialog_trim); shell.settext("swt test"); shell.setsize(new point(800, 400)); shell.setlayout(new filllayout()); text = new text(shell, swt.multi | swt.v_scroll | swt.read_only); shell.open(); while (!shell.isdisposed()) { if (!display.readanddispatch()) display.sleep(); } } void addmessage(string s) { text.append(s); text.append("\n"); } void close() { display.dispose(); } public static void main(string[] args) { testgui pr = new testgui(); pr.run(); pr.addmessage("add text"); pr.close(); } }
i run , see window cursor blinking reassuringly, nil else appears in it. not seem able create phone call addmessage() method run until close window, , of course of study shell disposed, exception.
i'm sure have missed key step...
thanks
chris
the problem while
loop in run
method waits until display is disposed, way run
method can finish after display disposed.
i'm not expert swt, seek moving while
loop main
method, or move call(s) addmessage
run
method. whatever way it, have add together messages before waiting frame disposed.
java swt paint
No comments:
Post a Comment