How to create popup hint window like Quick Doc in Intellij Idea? - java

I am developing a simple swing application and I would like to have something which can help user with it.
As example a little popup window will appear over "Start" button when user runs app first time and say "Hey, click here to start playing with me!"
Do you know the way to create something like quick doc in Intellij Idea?
Could you please put me on the right way to sources, examples, source codes or anything else which could be useful?
Below is example of how it can look like
PS. I have updated the picture.

As I said in the comment use javax.swing.PopupFactory to show popup for any component (which is probably not pointed by the mouse)
Popup p = PopupFactory.getSharedInstance().getPopup(component, new JLabel("It's a hint!"), 5, 5);
p.show();
component is the widget for which the popup must be shown.
You can also use the javax.swing.Timer to hide this popup automatically.

Tooltips are used in Swing to give the hover-over text that you are looking for. It is very easy to use a tooltip, all you have to do is set the tooltip text on your button
btnStart.setToolTipText("Hey, click here to start playing with me!");
Here is a pretty useful guide that explains the topic in more depth http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html

Related

How to Remove Automatic Selection on Text Field when I Start to run my Java Program

Good Day! Why whenever I start my Java Program, the JtextField is always selected even I am not selecting it. Is there any way I can remove it?
Kindly see the picture. Thanks!
The encircled JTextField is what I am talking about
Note, what you refer to by "selected" is called "focus" in Swing. That said, there's no such thing as "no component has the focus".
The best thing you can do is give the focus to a non-input element, like the "Information" title field.
Assuming that is a JLabel, you'd do something like
JLabel informationHeaderLabel = new JLabel("Information");
// ... layout etc
informationLabel.requestFocusInWindow();
There's a tutorial on the Swing focus subsystem.

Hear text (screenreader) when mouse hovers over a JMenu object in Java / Windows

When using a screenreader, like NVDA, I want to be able to hear the text of the menu when I hover my mouse over it. I am able to hear the text when I push the buttons in the menubar, but not when I hover over them (the screenreader does reads the menu's of other programs when only hovering over the buttons).
I have set the AccessibleContext like below:
JMenu.getAccessibleContext().setAccessibleName("text");
JMenu.getAccessibleContext().setAccessibleDescription("more text");
I can set listeners to the objects that detects when a mouse hovers over them, but I do not know if/how I can cast a text to the screenreader to read. I tried ToolTipText, but that text is not read by the screenreader either. RequestFocus on the JMenu works, but setting the focus to an object just by hovering over it with the mouse provides other problems.
Does anyone knows how I can let a screenreader reads the JMenu-text when hovering with the mouse over the menubar?
I am using Java6 EE and the Java AccesBridge (version 2.02) on a Windows machine (XP and w7).
Swing is the weaker of the GUI technologies relating to accessibility in Java, compared to SWT at any rate. There's a few things you can try.
First is to make sure any accessibility fields are set (which you've started on). I can't remember if Java has an AccessibleRole field, but you can try setting that to menu and menuitem for your menu items.
Another thing you can try is the AccessibleMenu JMenu.AccessibleJMenu component. This one's the product of further reading, so I can't verify it from experience. But it and its surrounding classes may suit your needs.
If those don't work, you could try the option of talking to people's screen readers directly. Quentin C has a good library to do this, Universal Speech. I'm new to this library myself, but it does have a Java implementation in there that should show you how to use it in a Java program. Normally I wouldn't recommend this approach unless making the UI accessible really isn't working.
The last option would be to use the SWT components instead of the Swing ones, even if just for your menu bar. I wasn't sure how keen you'd be on this one, but it is an option and should resolve it.
I hope one of these suggestions helps you solve your problem.

How to make "pages" in a java program

I have a question.
I just started with Java and may have some small basic things. Now I wonder how a kind of pages (sections) in a program makes.
I do not mean some kind of tabbed panel, or if you click on a button that a text is visible.
I mean that for example all over the screen a separate part of the program looks. As the main menu of a game.
There is nothing else than the main menu visible at that time. If you for example a button from that menu click. The game is loading.
(I'm using the building of a standard game as an example)
If you for example the main menu click on another button (eg "Settings")
Then wort settings "page" is visible, and there is nothing else that the program is really doing.
I do not know how this type of navigation is called. But almost every program does have something.
How can I do this too? What should I do for example, as a new file, import the classes of a particular page, or something?
You seem to be searching for CardLayout. As shown here.
I think you should look for "state machines", which is a way for structuring your code, and implement your menu changing swing components (like JPanel, for example) in a JFrame. If I understand what you want, I think this can be an option.
There is no short answer, but based on your question, you need to read alot. I would suggest the swing tutorial It explains use of Panels, Frames, Layout managers and other containers.
You can also use the Matisse builder in netbeans (relevant plugin in eclipse)

How would I go about adding a Radio Button to a popup menu?

I want to have a TrayIcon have a java.awt.PopupMenu. I already know how do this part. But it appears that Java doesn't have a RadioButtonMenuItem.
I already tried to add a JRadioButtonMenuItem to it, but that resulted in many errors.
Is there a way that I could incorporate 3 "checkboxes" that do not allow more than 1 to be selected at a time and add it to my PopupMenu?
My advice would be to use Swing - there's no reason I can see for using old AWT menus here. True TrayIcon is part of java.awt, but there is code around (see here) that works fine for me to integrate a swing menu with a TrayIcon.
And of course, once you're in swing territory you're away, just use JRadioButtonMenuItem.

How do I keep a dialog box always on top?

I created a dialog box like this:
String response =
JOptionPane.showInputDialog(null,"message","title",JOptionPane.PLAIN_MESSAGE);
I'd like to keep it always on top of all windows.
Do you have any idea?
Thanks!
In fact, using Java, having a system modal dialog is not possible. The best you can have is a toolkit modal option pane. That's to say an option pane that stay in front of all Java windows.
This example explains how Java6 allows you to do that.
Maybe I don't get the question, but I quickly created desktop app with code you posted and it actually is modal ...

Categories