Disable key-pressing in MessageDialog - java

I have a problem with my software developped in Java. The user has to write a text in a JtextPane. When there's no time left for him to write, a pop-up appears.
The only problem is : if the user is writting when the message pops up, the pop-up disappears because the key pressed validate the message.
Is there's anyway I can disable this fonction ?
I use this to create the MessageDialog :
JOptionPane.showMessageDialog(null,
new UTIL_LireFichierTXT().getText(MessageTempsImparti)
,new UTIL_LireFichierTXT().getText(MessageAttention),JOptionPane.WARNING_MESSAGE);
Thanks for reading.

Disabling normal application behaviour (such as manipulation of dialogs with keys) is not a great idea. It confuses a lot of users, who have been groomed to expect certain core functionality in GUIs, plus it can prove a real problem for users with disabilities, who may need to use keyboard navigation in place of a mouse.
I would suggest you consider a different method of telling the user the time is up. Perhaps a banner label appearing on the application somewhere?

Related

Java AWT Robot - how to read item text / label?

I need to select appropriate option from the popup window. Unfortunately, it is not the popup displayed by the web page, so I cannot use Selenium framework for that purpose.
As I checked, it is possible to navigate to different option by pressing arrow keys. Thus keyPress and keyRelease​ from Java AWT Robot should work for me perfectly to select option and confirm the selection by pressing Enter key.
Unfortunately, I do not see a method to read currently selected item text. Without that I cannot find appropriate option. Is it possible to read item label using Java AWT Robot?
If the target application is another java application, then you should be able to get a reference to the component hierarchy and traverse it until you find the text field & label in question.
Assuming it's not a java application, then I don't believe it's possible to do this - at least directly. Robot just provides mouse / keyboard input, but you could use it combined with other classes in the toolkit to at least partially solve your problem.
Use the Robot methods keyPress & keyRelease to input CTRL-A. Then CTRL-C.
Once the text is in the clipboard, you could read it using Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor)
You might be able to use the same approach for a text label, assuming it is selectable.
This question is talking about using java.awt.Robot to alter text in another program (MS excel), but it might provide you some additional ideas for tackling the problem:
How can I select text in another application with java.awt.robot (example: shift+home)

How do I find the bounds of a Win32 API text/edit control?

I am working on a program that will allow the user to record steps of simple tasks and then generate a file to send to people that show these steps. So if you left click on a window it will say "User Left Clicked on Google Chrome" with an appropriate screenshot and highlighted cursor for visbility.
I am using Java Native Hook Found here for the global mouse/key listeners and Java Native Access Found here to get the title of the application that is clicked.
I would like to include something that highlights an area where text is entered. At the moment I am thinking of taking a screenshot when the user clicks a textbox and then storing all the keys that are pressed (for the guide) and taking a second screenshot after the text has been input, and also adding a highlight outline around the text.
I feel like it would be easier to generate the highlighting if I could get the location of the caret but i'm not exactly sure how to do this for global applications.

JavaFX: how to disable drag and drop and pasting from external sources on WebView?

I am working on a chat application where I am using a webView to show the conversation between sender and receiver and another webView to write the message which will contain text and emoticons (the reason for using webView is that it is capable to show emoticons along text using html), the 2nd webView is editable by setting its contenteditable property to true in html, now the problem is that when I drag and drop text or copy text from somewhere which contains formatting, links and images it will be shown with all the formatting that is why I want to disable dragAndDrop and pasting text from external sources such as browsers, if the text contains links then by clicking that link it will direct you to that page and the webView will become a web browser.
Tricky (i think). One way to do it is by providing your own EventDispatcher instance and intercept the actions you want to prevent, e.g. intercepting the DragEvent to prevent drops and the key events for the paste action. The downsides to this approach are, of course:
1) You'd have to code platform specific for the paste shortcut (CTRL+V vs. META+V)
2) If you want to disable pasting via the context menu this way, you'd have to prevent it from appearing at all. However I think in your case that would be intended.
So, pending a better a better solution I'd go with the dispatcher. Determine which events you want to be processed and forward those to the dispatcher chain. Consume the events you want to prevent.

GWT- PopupPanel with search?

I am looking for a way to create a popup dialog box when a user double clicks a textinput field that will contain a scroll-able list (from database table) where the user can select a field, hit ok, and have it placed into the textbox when popup closes.
The other major requirement is to have a filter/ or search field in the popup to aid the user in finding the correct option to select from quicker.
What is the best way to implement this?
Modification to gwt's popup panel? maybe a JOptionPane? are there any simple solutions already designed for free commercial use?
You could implement this with a com.google.gwt.user.client.ui.PopupPanel. You can make a PopupPanel that contains a ListBox with your data from the database, along with a OK button. When a user selects a value and hits OK, you should utilize an EventBus along with a custom Event that will pass the value to the field on the page. The page will have an event handler that will catch the event and put it into the field.
Another option is to use a com.google.gwt.user.client.ui.SuggestBox. It is a box that autocompletes / suggests values as you type, kind of like the Youtube search bar.
I can offer more resources to help you accomplish this, if you'd like.

What is the purpose of onSearchRequested()?

What is the purpose of onSearchRequested()? I am referring to here: http://developer.android.com/reference/android/app/Activity.html#onSearchRequested%28%29
The following is stated: "You can override this function to force global search, e.g. in response to a dedicated search key, or to block search entirely (by simply returning false)." Specifically, what does the bolded piece mean? Does it not mean that we are able to disable this button? I just had a heated discussion at: Android - How to disable Search button, how to implement onSearchRequested()?
As you can see, Phil is suggesting that I have to go the other route. My questions are: can JUST this function be used to disable the search button completely? Can just this function be used without having to disable this button from the dialog builder? What did google meant with the above quoted statement? Thank you for your time.
You should be able to disable the search button using it, i would think google mean that you can block someone trying to search from within your app( IE skipping a progress dialog)
but since most android phones don't come with search buttons anymore, its not a very used function.
and yes you should be able to disable it on the fly without going through the dialog builder.
Swift

Categories

Resources