Java "Create New" window - java

I'm relatively new to GUI with Java and I have a JFrame with a simple menu bar with your typical create new button(Like create new file and stuff). I want to have it so when I select this button another window pops up and it has several things to fill out after which you select an ok button or a cancel button. Then the focus is returned to the main JFrame.

This sounds like the perfect job for a JDialog. Dialog tutorial.

Related

Advice: Java GUI Using JFrame

I Have created a form and designed it using Swing Components. It is linked to MySQL, so i have few buttons, like Submit (Which When Clicked validates and updates the database). But I also have buttons to view and edit database. When clicked i have worked on Delete Record using JOptionPane (YES_NO_OPTION etc), but when it comes to editing, i want to put Combo boxes and Text Fields etc, which might not be preferred in JOptionPane. Creating a new Window would help, but is there any other easier Default Classes like JOptionPane in which i can use Many components? Also to display Database records?
I believe what you are looking for are JDialogs, these are the "small" popup windows you are looking for. You may add any swing component you wish to it.
Here is an example of creating one and adding a JTextField to it.
JDialog popup = new JDialog();
//Set window title
popup.setTitle("Example");
//Set window size
popup.setWindowSize(300, 200);
//Force window to stay on top till exit
popup.setModal(true);
//Create and add a JTextField
JTextField input = new JTextField();
popup.add(input);
popup.setVisable(true);

Multiple windows in eclipse window builder

I am using Google Window Builder for eclipse to create the UI aspect of my program. I need to create a preferences window so that the user can change different settings for the program. I want the user to be able to press the 'preferences' button in the menu to bring up a separate window. The problem I am having is that I do not know how to create or add components to this separate window visually through Window Builder. Is there a way I can create a jpanel that is not a child of the main jframe program through Window Builder?
Right click on the package where you want the file for the new window to be stored. Go "New -> Other" and select "WindowBuilder -> Swing Designer -> JDialog". Write in a name for the class of the new Window. That will bring up an editor, select "Design" tab at the bottom of the window. Now you can customize this new window.
To open this window from your main JFrame you'll need do this:
MyNewWindowClass newWindow = new MyNewWindowClass();
newWindow.setVisible(true);

how to restrict more than one java application icon on taskbar?

I have created an application in java which have several forms.
During application start getting open new form on button click event,On windows's taskbar the number of icons of that form getting increases.
what I want is only applicatoin icon should be displayed on task bar whether one form is open or more than one.
The problem happens because each JFrame gets a task-bar icon. See The Use of Multiple JFrames, Good/Bad Practice? for links to a multitude of solutions.
I think this tutorial will help you to solve your task.
Multiple Document Interfaces with JDesktopPane and JInternalFrame
If you already have your new window as a JDialog and are still facing the problem of having two icons in the taskbar, it may be that you are creating your modal JDialog like this:
JDialog dialog = new JDialog((JFrame) null, true);
With owner (first) argument set to null, the application creates a new icon in the taskbar for the dialog. So, to avoid this, just pass the reference to your frame to the dialog constructor when opening the dialog (e.g. by clicking on a button). Like this:
public class MyBrandNewDialog {
public MyBrandNewDialog(JFrame owner) {
// create new modal dialog (the second argument is for modality)
JDialog dialog = new JDialog(owner, true);
// ...
}

Java: Show JPopupMenu without passing an invoker component

When I let popup a JPopupMenu without passing the "invoker component", the menu doesn't work: submenu's don't open and isn't getting repainted. But when I create a completely useless JFrame with a JLabel inside, and I pass the JLabal as invoker, it works correctly...
Any suggestions, how to avoid creating a useless frame. And my application really hasn't any frames open, it just has to popup a simple menu.
JPopupMenu.show(null, xOnTheScreen, yOnTheScreen); // Doesn't work
JPopupMenu.show(aStupidJLabelInAStupidJFrame, x, y); // Works
Thanks
Take a look at JPopupMenu source code and you'll see why you have to set an invoker.
Showing a popup menu without any existing component would be very bad usability, in the same league as popup windows from a browser.
Why can't you use JComponent#setComponentPopupMenu, or add a mouse listener to the component in which you want to show popup menu?

Java: How can I add a JMenu to a JPanel or create a drop down button?

is there any way to add a JMenuItem to a JPanel so that I can create a button to show multiple options, like the latest news button in firefox, under the address bar?
I can only add JMenu and JMenuItems to a JMenuBar, JPopupMenu and other JMenus and JMenuitems
Is there any way to create in Java Swing a drop down Jbutton? (the ones with an down arrow in their left which shows more options to the user)
Thanks in advance
Finnally i implement the "show options button" with a simple Jutton, and a JPopupPane with the options to show:
In the ActionPerformedListener of the button i write this code:
popMenu.show(showOptionsButton,0,showOptionsButton.getHeight())
It works fine like a JMenu in a JMenuBar, but not exactly like a dropdown button, in which you can perform an action pressing the button or show more actions pressing the down arrow. I believe this can be done ussing two buttons "very close", then use the code above in the arrow button, but setting the "action button" as the component of the popup, so that the popup shows below of both buttons.
A JMenuBar should only be added to a JFrame (setMenuBar()), not a JPanel.
A Swing drop down button is the way to go here.
See this article for a good discussion on various implementation propositions
alt text http://blogs.sun.com/geertjan/resource/dropdownbutton1-jl.png
The above drop-down button use the NetBeans UI Utilities API (platform7/modules/org-openide-awt.jar in any distribution of NetBeans IDE). You do not need to have NetBeans to run it: only this jar you have extracted from the NetBeans installation.

Categories

Resources