Scenario:
Pickup some data from an Excel file.
Search for it in a Text file.
If the data is not found, display a popup message box with a 'Retry' option.
User opens the Excel file and changes the value.
Click the 'Retry' button.
The Line which threw the error earlier should get executed again.
I need to know, how to display a message box with a 'Retry' option, clicking on which shall execute the line of code again.
Just place the code that pops up the box in a loop and continue the loop if the retry button was clicked. The response code from the jOptionPane tells you what button was popped.
this will give you an option pane with 4 buttons java C++ VB COBOL
String[] choices = {"Java", "C++", "<acronym title="vBulletin">VB</acronym>", "COBOL"};
int response = JOptionPane.showOptionDialog(
null
, "Which is your favourite programming language?"
, "Language Poll"
, JOptionPane.YES_NO_OPTION
, JOptionPane.PLAIN_MESSAGE
, null
, choices
, "None of your business"
);
Related
I am trying to create a GUI for my program. This particular GUI uses a JOptionsPane with a showOptionDialog. I have added a panel to that OptionsPane that has some action listeners as well as two lists and some other things, that really doesn't matter for this question though.
Quite simply I want my showOptionDialog to perform some action when the user clicks the "cancel" button. (It will basically end the program but it must be done in a certain way). Right now when the user clicks "cancel" the program continues as if the user just ended that dialog but no action is taken. I am trying to change a variable if they click cancel which will prevent the rest of the program from running. I tested with a System.out.println to see if my value was really being changed and I found that the step wasn't occurring at all. So I would like to know based upon this code what I am doing wrong. What do I need to do to make the code run correctly when the user clicks cancel?
I do not have more code to show as my program is very large and it is impossible for me to isolate this situation.
Thanks in advance for the help!
public static void displayGUI(){
int result = JOptionPane.showOptionDialog(null, getPanel(),"JOptionPane Example : ", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, new String[]{"Confirm","Create Return"}, "default");
if(result == JOptionPane.CANCEL_OPTION){
initialScreenDecisions="NONE";
MainWriter.finishedCounter=true;
System.out.println(MainWriter.finishedCounter);
while(MainWriter.entryDetails.size()>0){
MainWriter.entryDetails.remove(0);
}
while(output.size()>0){
output.remove(0);
}
}
}
*This part of the code isn't being executed, even if the user selects cancel:
if(result == JOptionPane.CANCEL_OPTION){
initialScreenDecisions="NONE";
MainWriter.finishedCounter=true;
System.out.println(MainWriter.finishedCounter);
while(MainWriter.entryDetails.size()>0){
MainWriter.entryDetails.remove(0);
}
while(output.size()>0){
output.remove(0);
}
}
From your Question:
*This part of the code isn't being executed, even if the user selects cancel:
Try The integer value that is returned from the JOptionPane.showOptionDialog(). 0 Is returned if OK is selected and 1 is returned if Cancel is selected.
Modify your code as follows:
if(result == 1){
initialScreenDecisions="NONE";
MainWriter.finishedCounter=true;
System.out.println(MainWriter.finishedCounter);
while(MainWriter.entryDetails.size()>0){
MainWriter.entryDetails.remove(0);
}
while(output.size()>0){
output.remove(0);
}
}
Let me Know, If this doesn't Helps you!!!
You are telling JOptionPane to create two buttons ("Confirm" and "Create Return"), and then telling it the default button is "default" but you don't have a button with text "default". You also don't have a Cancel". The return value will be 0 if the uses picks "Confirm", or 1 if the user picks "Create Return", or CLOSED_OPTION if the user just closes the dialog.
If you take a look at the JavaDocs for JOptionPane.showOptionDialog, it tells you
Returns: an integer indicating the option chosen by the user, or
CLOSED_OPTION if the user closed the dialog
This is the index of the options array you passed to the method. In this case new String[]{"Confirm","Create Return"}
So a return value of 0 will mean Confirm was selected and 1 will mean Create Return was selected (or JOptionPane.CLOSE_OPTION if the user closed the window)
When assigning result a value you are using JOptionPane.OK_CANCEL_OPTION but in the if condition you are checking for JOptionPane.CANCEL_OPTION
Usually, my AHK program reads the content of the "Filename:" text zone in file dialog boxes (Open, Save As, etc.) using the following info: read the content of control "Edit1" in dialog box of class "#32770". It can also read the list of controls using this piece of code:
; in Notepad, open the "Open" dialog box
WinGet, strControlsList1, ControlList, ahk_class #32770
WinGetTitle, strTitle1, ahk_class #32770
MsgBox, , %strTitle1% controls, %strControlsList1%
I'm trying to do the same in Java programs implemented for Windows (PDF Split and Merge and Geogebra) using Java Access Bridge, I guess. I know that these programs use the class name "SunAwtDialog" instead of the usual "#32770" for their dialog boxes. But I can't get access to the "Filename" control name. "Edit1" does not work. And I can't get the list of controls in this dialog box using this code:
; in a Java app like PDF Split and Merge, open the "Save As" dialog box
WinGet, strControlsList2, ControlList, ahk_class SunAwtDialog
WinGetTitle, strTitle2, ahk_class SunAwtDialog
MsgBox, , %strTitle2% controls, %strControlsList2%
Any idea how an AHK script could get info from these Java apps dialog boxes?
I am unable to press 'Go' button on searching something on Nexus 7' tablet. We don't have any text or content description for the 'Go' button on the keyboard. I tried using following -
//Search something say "fun"
new UiObject(new UiSelector().text("Enter URL or Search & Win")).setText("fun");
getUiDevice().pressEnter();
OR
getUiDevice().pressSearch();
Also tried :
getUiDevice().pressKeyCode(66); //for enter
getUiDevice().pressKeyCode(84); // for search
But this is not working.
Could anyone help me out with this.
Thanks
Try using the button attribute with reference to index.
i.e :
UiObject cancelButton = new UiObject(new UiSelector().className("android.widget.Button"));
To click on "Done" button with UIAutomator just try below code
use
just make sure that correct layout in which input keyboard is open is used
UiObject(new UiSelector().resourceId(LAYOUTID)).clickBottomRight();
First, the code:
tab_textArea_file.addTab(docLabel, null, scrollPane_textArea, null);
So the situation is that I have a list of files the user can select from. When a user clicks on a file, the contents of the file is read and loaded into a textArea. "docLabel" (which is in the code above) is the string that's suppose to change to the name of the file selected, but it doesn't. Is it possible for to change the name within docLabel from the code above? I've tested it with a JOptionPane (works), but it's not working within a tab.
Have you tried something like
int index = tab_textArea_file.getSelectedIndex();
tab_textArea_file.setTitleAt(index, "New Title");
from java doc i see
setTitleAt(int index, String title)
you could take index of tab clicked and change is name
You can know the selected tab index by calling
int selectedIndex = tabbedPane.getSelectedIndex();
and then after your file is selected call
tabbedPane.setTitleAt(selectedIndex, "New Name");
I've had issue with the setTitleAt(int index, String title) : If the title doesn't appears, try to replace:
tab_textArea_file.setTitleAt(index, docLabel);
with:
tab_textArea_file.setTitleAt(index, new String(docLabel));
I am working on J2ME application. I want to show alert in Form and display another Form from another class. I have tried the following method to show alert.
public void showMsg()
{
Alert success = new Alert("Data Not found.");
//success.setImage(img2);
success.addCommand(new Command("Ok", Command.OK, 0));
success.addCommand(new Command("Cancel", Command.CANCEL, 0));
success.setCommandListener(this);
success.setTimeout(Alert.FOREVER);
Display.getDisplay(parent).setCurrent(success, chapterForm);
}
After showing the alert I am jumping to another form as:
Display.getDisplay(parent).setCurrent(welcomeForm);
When I run this it don't show the alert but jump to the welComeForm. So, how can I show alert and then jump to another form.
The Alert won't advance automatically to chapterForm because you have replaced the default listener on the Alert with this. Use the commandAction() event in the CommandListener interface to get the OK or Cancel from the Alert. Then you can use Display.setCurrent(Displayable d) to show the Form you want to display.
Display.getDisplay(parent).setCurrent(welcomeForm) is most likely the reason why it don't show the alert but jump to the welComeForm. To be precise it (device) may show alert for a moment, but as soon as you invoke that setCurrent(welcomeForm), it gets momentarily overwritten by welcomeForm.
If you want welcomeForm to be dissplayed by command from alert, just
wipe out the code setCurrent(welcomeForm) from where it is now
insert that wiped-out code into this.commandAction method (this is command listener you use in your code exerpt)
A nifty solution is to start a new thread after setting the current display to the Alert, and in this new thread you can do a Thread.sleep(2000); in order to wait, and after that you display the new form.