I've a problem with a Java Project, using SWT library. It's my first time trying with SWT, so don't throw stones to me please.
Environment: Eclipse - Juno
Class and functions:
1º Client -> Where's "main". Creates a object of "GUI_Creator" class (mine).
2º GUI_Creator -> Has 2 functions, in order to "desing" my forms.
2.1 -> MakeLogIn -> Void method, wich adds the controls i need to the Shell i give him as parameter. I use it, to desing the first form i show to the user.
This function also link the "click" event of a button of this shell, with the second function of GUI_Creator class, that creates a new one shell. Then, this shell would be open, and first one would be closed.
2.2 -> MakeClient -> This function returns a shell var. For me, this returns the second shell of my program, even with the desing, etc.
Problem:
I'm using, at the end of "main" this code:
while (!Conexion.isDisposed())
{
if (!ourDisplay.readAndDispatch())
ourDisplay.sleep();
}
ourDisplay.dispose();
If i'm not wrong, this code is doing that when i try to close my first shell, and then leave only opened the second shell, my program closes completely, because i'm disposing the parent display.
However, i can't delete this code, because if i do this, when i run my program, it doesn't "wait" an action, and just executes all "main" code and then closes the GUI and the program finalizes.
So, i really don't know what would i have to do, in order to fix this situation.
Thanks,
Btc
I'm not sure if I got your problem right, but you could try:
while (!(shell1.isDisposed() && shell2.isDisposed())) {
...
}
Related
I'm currently working on building my first app. :)
I've now coded several Forms, each in an own class. Now, I want to implement the navigation from one Form to another, this is pretty straight forward since there is always only one "next" Form for every Form currently.
So i tried to do this by adding a "nextForm" Form to every Class and I want nextForm.show() every time the "next" Button is pressed. I tried it this way:
login = new Button("Login");
login.setUIID("nxtButtons");
login.addActionListener((e) ->
nextForm.show()
);
So, when i actually click the button, nothing happens.
Is the way I try to code this a good way? This is the first time Im heading into GUI building and I don't have experience here yet. Maybe one of you guys could help me here :)
Thank you very much
Kind regards,
Max
I'm assuming nextForm is null and you should see the null pointer exception in the console somewhere.
If not nextForm might be pointing at the current form which will do nothing. You can place a break point on that line in the debugger and see that the break point is reached then inspect the values of the variables.
In my RCP application, I created multiple WorkbenchWindow. Once multiple windows are opened, I would like to bring one of them on top programmatically. In my code, I can find out "theWindow" (type of IWorkbenchWindow) that I want to do that, but I'm not sure how to bring it to top (set it active?)
Can you try the following :
theWindow.getShell().setFocus();
If that doesn't work , try calling the forceFocus() on the same shell.
Thanks to Rambler for the hint of forceFocus(), the actual function that does the trick is:
theWindow.getShell().forceActive();
I think this is so wrong, but I need it...
So, to run Processing's sketch in Java mode, you have to extends PApplet in the main class, and there, in the setup() determine the window size using size(int x, int y). Then when you run it, it'll show a Java window Applet Viewer.
What I wanna ask is, how to prevent that window from appearing? I've tried to remove the size method, but it appeared in (what seems like) it's default size. Tried put 0 as params, went wrong (the x and y have to be > 0).
Is there any way to do that?
If there's any lack information or I've made a mistake with the post, please tell me.
1st edit - add more info
Let's say I have 2 classes: the one that implemented Processing and extends PApplet is named Pikachu by me, and an ordinary Java class I named Jojo. Jojo will pass params to Pikachu and Pikachu will process that param. The param is image's name, or if it could, an image itself (I don't know yet tho, can Processing execute Image class from Java?). Then Processing will process that image, gave an output, again as image (Yet, again I don't know yet, can Processing gave output an image for Java to use?). So, that's why I don't need a window to appear.
Perhaps you can try to use the Frame object.
In the documentation there is a function .setVisible(boolean b)
If you call .setVisible(false) you can turn the frame off.
http://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#setVisible(boolean)
I am not sure how to access the frame using pure Java. In processing you can simply call
frame.setVisible(false);
Hope this helps
I have mixed some different types of command like OK,CANCEL,BACK,EXIT,SCREEN in my application.
For Example,
exit = new Command("Exit", Command.EXIT, 5);
_123=new Command("123",Command.BACK,4);
ABC=new Command("ABC",Command.CANCEL,3);
sample1=new Command("Sample1",Command.SCREEN,1);
sample2=new Command("Sample2",Command.OK,2);
The Order i need is :Sample1,Sample2,ABC,Exit. But it Display like this Sample1,Sample2,Exit,ABC are right side and 123 is placed in left side button.
Here, I also have one problem while adding one more command(Edit_Cell) using like below.... and also i need to display in the first place before Sample1.But it displayed in End of all the commands on right hand side.
I have added this new Command(Edit_Cell) in another src file constructor and call that constructor in below of my above code(adding commands).
Edit_Cell is type of SCREEN and PRIORITIES IS 1 on the other source file.
My Final Order i need is : Edit_Cell,Sample1,Sample2,ABC,Exit, on right hand side and _123 on left hand side.
First of all, and without offense, I think you should elaborate a bit more your written compositions, it took me a while to understand the issue.
Still, the way you claim commands makes sense according to this (Nokia's wiki forum):
The Command mapping to softkeys follow following rules:
Right softkey: There can be only one
"negative" Command (STOP, CANCEL,
BACK, EXIT in this priority order)
mapped to Right softkey, and the
Command mapped there is directly
invoked by softkey press.
Left softkey: Mutiple commands can be
mapped under Left softkey in which
case there is "Options" label in Left
softkey and selection of it will open
a menu of commands. If there's however
only a single "positive" Command (OK,
ITEM, SCREEN or HELP) under left
softkey it will be presented directly
on Left softkey. (Note: Some LCDUI
components have their own operations
that will be also visible under left
softkey thus forcing Options menu.) If
there's more than one negative Command
this will force Options menu on Left
softkey and the commands will be
presented in the order define below.
Middle softkey: In Series 40 only a
single context sensitive Command (OK,
ITEM) is mapped to Middle softkey. In
S60 multiple context sensitive
Commands (OK, ITEM) can be mapped to
Middle Softkey. If there's only single
Command it will be shown directly in
softkey, otherwise commands are
visible in context sensitive menu
opened from middle softkey. Normally
the same commands mapped to Middle
softkey are also available in Left
softkey (directly or via Options
menu). Note: Some UI components
override this rule and place component
specific operation directly to Middle
softkey. For example, POPUP
ChoiceGroup has "Open" operation in
Middle softkey.
Obviously this depends a lot on the platform, but it seems your midlet is assuming _123 as the negative Command, and all others are placed on the other soft key.
I would try to change the types and set the priorities as you wish... something like this
exit = new Command("Exit", Command.EXIT, 5);
_123=new Command("123",Command.BACK,0);
ABC=new Command("ABC",Command.SCREEN,3);
sample1=new Command("Sample1",Command.SCREEN,1);
sample2=new Command("Sample2",Command.OK,2);
And you can set the priority of Edit_Cell to 0 and its type to SCREEN. And just to add: ITEM commands are usually placed before.
I hope this helps.
Regards.
I reply to your comment here, it's less messy...
Maybe it's displaying the commands in the same order they were added (not using priorities). I would delete all commands when Edit_Cell is added and add them all again, after Edit_Cell is added.
If you can only modify your form's code, then you can override the addCommand method to ensure when Edit_Cell is added all previous commands are removed and added again later.
Something like this:
#Override
public void addCommand(Command cmd) {
if (cmd.getLabel().equals("Edit_Cell")){
removeCommand(sample1); // with all the previously added commands
}
super.addCommand(cmd);
if (cmd.getLabel().equals("Edit_Cell")){
addCommand(sample1); // again with all your previously added commands
}
}
It's not very elegant, but well, you can always make it more classy, as long as it works....
I'm trying to get data for my application from a form set in an external window (getDataWindow extends javax.swing.JFrame). The problem is that functions are executed before form is filled in.
getDataWindow dataW=new getDataWindow();
dataW.setVisible(true);
size=dataW.returnSize();
I've tried also adding additional boolean variable to getDataWindow
getDataWindow dataW=new getDataWindow();
dataW.setVisible(true);
while(!dataW.checkIfReady()){wait();}
size=dataW.returnSize();
But it makes also the window wait (it appears but it's black inside and nothing happens).
I think i should create some threads for that - I've tried to call a window making function getDataWindow in java.awt.EventQueue.invokeLater(new Runnable()) but I had to initialize dataW earlier so dataW.checkIfReady() could be called, so it is a catch 22.
Have you tried adding a listener in form contained fields ? I know you don't have full control over that class, but, well, it's some java code ! Run it in your debugger, and you'll see the code organization for that DataWindow. Then, you'll be able to add a Key/Action/Anything/Listener to trigger your code execution.