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);
// ...
}
Related
i have displyed this JDialog , and have passed an Object which is a JPanel on it , thus my JDialog displays my JPanel on it when Invoked as required.
and on this JPanel I have a JButton, on pressing i want some operations to happen which i have written in it's ActionListener and in the end i have to dispose that JDialog, but i have no clue how to do it !!
This s my JDialog Statement and help me with HOW TO EVEN REMOVE AN ICON from JDialog as even after keeping the ICON PARAMETER NULL it displays the ICON.
JOptionPane.showOptionDialog(null, "SELECT ITEM AND THEN EDIT THE DETAILS.",
"EDIT ITEM DETAILS", int1, int2 , null, objEditMorePane, null);
It sounds like you want to make it a JOptionPane.PLAIN_MESSAGE. That is what you need to put instead of whatever int2 is. I was going to link you to the tutorial but Space Pope already did that. You don't need to create a custom dialog to change the default icon, just change the message type to a plain message. The tutorial covers all this stuff.
You'll need to keep a reference to the dialog if you want to close it yourself. See the Oracle tutorial on custom Dialogs. The constructor you're using also puts in an icon by default; if you make your own dialog, you can control that part too.
JOptionPane closes its dialog when its value property changes. So, you can obtain the parent JOptionPane and set its value to close the window:
JOptionPane optionPane = (JOptionPane)
SwingUtilities.getAncestorOfClass(JOptionPane.class, button);
optionPane.setValue(JOptionPane.CLOSED_OPTION);
If the window wasn't created by JOptionPane, you can use the getTopLevelAncestor method of JComponent to obtain the parent window:
Window window = (Window) button.getTopLevelAncestor();
window.dispose();
I am programmi an application for mac and I would like to have an about window to show to the user some infos, like the one of Finder.
Actually I am using this code:
System.setProperty("apple.laf.useScreenMenuBar", "true");
// SET NAME IN THE MACMENUBAR
System.setProperty("com.apple.mrj.application.apple.menu.about.name", Constants.APP_NAME);
Application application = Application.getApplication();
Image image = Toolkit.getDefaultToolkit().getImage("res/logo.png");
application.setDockIconImage(image);
application.setAboutHandler(new AboutHandler() {
public void handleAbout(AboutEvent arg0) {
JOptionPane.showMessageDialog(null, "Some infos.");
}
});;
but the thing that I obtain is not what I want, because is a dialog box with the "logo.png" image on the left and the text on the right. And also a big awful "OK" button that you must press to close the window.
How can I make a simple about window like Finder's ?
Can you help me? I found many tutorial on the net, but all are using deprecated methods in Application class.
(sorry for my bad english, I am italian)
You have at least two options:
Create a JPanel (possibly your own subclass) and layout the components in it as you want. Then show it with JOptionPane.showMessageDialog() by passing it as the first argument, rather than passing null as you have.
Create a JDialog and layout the components yourself. Again, you may want to create a subclass of JDialog to do this.
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.
We have an application which, as its first UI action, displays a modal JDialog without a parent frame.
public LoginDialog(Frame owner, Config config, Object... params) {
super((Frame)null, true);
It unfortunately has the annoying characteristic that when it appears, although it comes to the front, it does not grab the focus.
So the user, after launching the application by double-clicking on the start menu, has to use the mouse to select the "login" dialog and type in information.
Is there a way to make this JDialog grab the focus when it appears in the front?
I've tried calls to "requestFocus" before, after and via invokeLater "during" the call to setVisible(true) - but none of these seems to have any effect.
How do we make a modal dialog grab the focus?
UPDATE: The issue was the code used to try to present a background "wait window". This window was displayed "behind" the login dialog as a hack so that when the dialog disappeared the user would see the "Please wait" message. As it was the first window created by the application, it got the focus. I am not sure if there would have been a way to make the dialog gain the focus again inside the event dispatch thread with this hack - but I fixed it by un-hacking it and doing things properly.
First, it a little strange that modal dialog is parent-less. The point in modal dialog is that it is displayed on its parent and does not allow to access parent.
So, the first recommendation is to make it non-modal. I believe it will work.
BTW I have just tried to create such dialog and have not problems with focus. Try probably to simplify your code:
JDialog d = new JDialog();
d.setSize(200, 200);
d.setVisible(true);
This works for me and I believe will work for you. Now start changing this simple code towords your real application code. At some point it will stop working and you will see where the problem is.
If nothing helps try to use the trick I described in this article. Look for title "Portable window activation". I hope it will help.
See Dialog Focus for a potential fix using a RequestFocusListener. I have used it successfully for setting focus in JOptionPane dialogs.
1) you have to create JDialog contents and showing container wrapped inside invokeLater()
or best and safiest way is
2) you have to set for ModalityTypes or Modal for parent
3) only one from containers could be Modal in applications lifecycle
I've been trying to change a jFrame to a jDialog so it inherits the icon of the main window but I don't have a clue how to do that. I tried setting it's code from public class jSemestriala extends javax.swing.JFrameto public class jSemestriala extends javax.swing.JDialog but that didn't change the icon of the window. Any ideas? I'm using NetBeans 7.0.1
The JDialog takes its icon from the owner frame.
You have two options:
Create an invisible JFrame, set your icon to it and set that frame as owner of the dialog.
Create the Dialog, get the owner, and set the icon to it.
I would choose the first option, it seems saver to me. The second one makes use of the (shared) owner of the dialog. This could cause side effects.
For further reading.
But if you already have an main frame, you simply need to set it as owner in the constructor of the dialog.
You need to specify the "main window" frame as the owner of the JDialog:
// ownerframe is a JFrame;
JFrame ownerframe = new JFrame();
JDialog dlg = new JDialog(ownerframe);
JDialogs have owner frames. The frame is either created for you if you call the constructor new JDialog(), in which case the frame is invisible; or you supply it to the dialog in its constructor using new JDialog(ownerframe).
create a new jdialog
hard copy the components from design view of jframe(you can use navigator window to copy all in clearly. ofcourse just copy the components under jframe)
paste it on jdialog(again use navigator window . ofcourse paste under jdialog)
hard copy the source code from jframe's source code window
paste it on jdialog's source code
do not touch the automaticly created codes
if you need it, add them again by using design window.
fix the errors in source code window of new jdialog by using your eyes and hands :)
remember all the time: be careful about choosing the type of class form.
sorry for my english.
it could take a long time but it will work.