I am developing a Java application using Swing. I am using menu bar in my application. Whenever I click a menu item I need to open a new panel/frame within the window containing menu options.
To be precise I don't want to open a new window on clicking a menu item. What is the possible solution to this problem?
Thanks in advance.
If you want to put windows inside of other windows, you should look at JInternalFrame:
http://download.oracle.com/javase/tutorial/uiswing/components/internalframe.html
If you don't want to open a new window when clicking a menu item, CardLayout is a good choice. Also, don't overlook the convenience of using actions in your menus.
Related
I'm currently working on a school assignment where I need to create an app for visually impaired users. I would like to use Java with JavaFx for GUI.
Preferred element for visually impaired users is menu bar, since it can be easily navigated by keyboard. Menu bar in JavaFx is a MenuBar class object, that has Menu class attribute, which has MenuItem class attributes. Windows Narrator (neither the NVDA screen reader) works with this menu bar out of the box. It won't read the labels at all. It just says "Menu" and that's it.
Menu and MenuItem do not have accessibleText attribute which stores the text to be read by the screen reader software. Is there a way to make this menu bar screen reader compatible?
TL;DR: Is there a way to create menu bar that works with Windows Narrator in JavaFx?
For future reference: I've managed to solve this. The issue was I didn't have Java Access Bridge enabled (https://docs.oracle.com/javase/7/docs/technotes/guides/access/enable_and_test.html). Enabling it made the menu bar work without any other changes.
I am using the JFrame feature in NetBeans in order to make it simpler to customize and edit. In my program, clicking a button calls an action that displays a dialog box. I want to have an image inside of that dialog box. In NetBeans along with its JFrame editor you can add boxes and customize them, along with a dialog box. Which means it will be easier to edit that dialog box.
How to I call that custom dialog box to display when the button is clicked?
To put it more simply without the need for puting code. I have created a cusome dialog box in netbeans GUI builder. Now, how to I call/use that custome dialog box inside of my actual JFrame, which was also coded inside the netbeans GUI editor, and is located inside the same package and all.
First Drag and drop Swing Windows >> Dialog.
Then inside your code write this line to show it
jDialog1.setVisible (true);
After that double click on the Dialog design and add as many components as you like
Best Wishes
I made a Checkbox so where when you click it it opens another window with more checkboxes. How is it you would go about making those checkboxes open another window?
Have you tried adding an actionlistener to your checkBox component?
It's hard to see what excactly you're trying to achieve; but from what you write it shouldn't be more than that.
You can try this tutorial, for starters:
http://www.java2s.com/Code/JavaAPI/javax.swing/JCheckBoxaddActionListenerActionListenerlis.htm
I want to add a window on clicking the menu item of a right click popupmenu in Java swing(seems like a simple task...but not getting)
I got it to partly work by
adding a custom menuitem in popupmenu
adding a window on right click
But this only partly works. Now I when I right click anywhere a window pops up, but the selected menu item in the popupmenu does not pop up the window.
How can I get window on clicking my menu item? or is there an easier way to do this in java?
I know there are others ways of doing this (in code), but I would prefer to use Java swing
Has anyone ever done this before?
Thanks for your help
please to read Oracle tutorial about How to Use Menus
How to Use Swing Actions and / or with How to Write an Action Listener
a few examples about JPopup /JPopupMenu
i want to add a popup menu to my app but when i add it to my panel i see its disappear.
how i can edit jpopup menu visualy like other menus?
I think you're talking about using the matisse visual designer in NetBeans.
In which case the process is slightly different from creating menubar menus that you can just drag onto the screen.
The steps to get this to work are as follows
Drag a pop up menu on to the screen
Go to the Inspector Window (Window -> Navigating -> Inspector)
You will see an element there - jPopupMenu1
Right click jPopupMenu1 -> Add from Palette
This submenu will show you all the items that can be added to your pop-up menu
After you have selected the item you will see it listed as a child node of jPopupMenu1.
To change the order of your menu items, select an item, right click and select move up or move down.
Don't forget that although you've added the pop-up menu to the form you still need to register the pop-up menu with the component that you want it to activate for, the easiest way to do so is via SetComponentPopupMenu().