How do I determine if a JDialog has children? - java

I've got a custom window class that is a couple levels down extending a JDialog. We have windows that we create and sometimes we create new windows as children of existing windows using the constructor that takes a parent argument.
I need to put some code somewhere in our custom class that does something different depending on whether not the window has children. I know of getParent(), etc, and I can see that I can loop through the components of the window, but for the life of me, I can't seem to figure out how to determine whether or not my current window has any child windows.
Is there a way to do this? Any help is, as always, much appreciated.

See Window.getOwnedWindows().

will getOwnedWindows() do? It belongs to java.awt.Window which in JDialog's parent lineage.

Related

How to set multiple window owners in javafx?

I know it's probably not possible, but that is the best way to describe the resulting effect. I need to make a window always on top of a certain set of other windows, much in the same way that a child window will always stay on top of its parent. The thing is, now I want to have multiple "parents". How do I do that? I know it's possible since the GIMP application does it with its toolbox.

Change information in a dialog box from another dialog box in WindowsBuilder?

In windowsbuilder, I would like to change information from a seperate window, more specifically a table, from my main window. Is it possible to use my information from one seperate window to change it in another box?
Basically, take information from here:
And put it into this table:
Is it possible? If so, how? Thank you in advance.
Yes, it is possible - but not in Windows Builder.
Create an object which will hold the information from the first window and pass the information from the window to the object. Next, pass the object to the second window (how you do this will depend on how you've configured your window objects). Finally, populate the table with the information from the object.
As far as I know, there is no direct way to do this in Windows Builder, although the above method will work fine provided you can pass objects from the first window to the second.

Creating a GUI Class in Eclipse

What I'm thinking of doing is creating a class for my little subview, so I can use it over and over again. Specifically, in my project, I need a colored rectangular and a label, and between those subviews those are the ones gonna change. Thus, I want a class that represent that two components as one component.
I'm trying to use swing. Before, I used acm package which gave me convenient way of doing it, but I can't solve that problem with swing. So, the problem starts here, I couldn't figure out how to create a custom GUI class for a subview.
I want to put them in a for loop later, so I want to handle the case in once rather than writing for 20 times manually.
Any help would be appreciated,
Create your custom class so that it extends a JPanel. From there, you can add your common subcomponents, which sets each one up by passing parameters through the constructor, and then implement any common behaviours with methods on that class.
You could try Window Builder plugin for eclipse for drag and drop editor. You could try to figure what's going wrong by organizing you objects.

Java Web Start application shows empty window on XMonad

I use XMonad+gnome as window Manager. I have the problem that, when I run a Java Web Start applicacion, It olways show an empty window, like the screen:
Is there something I can do to fix it?
UPDATE:
I tried simple programs from JWS Examples and it works, right. So it should be a problem of the application.
The failed aaplication is Blast2Go.
Change the name of the window manager to a known one like LG3D:
startupHook = setWMName "LG3D"
I had the exact same problem with my own Java code and using the other suggested solutions (setWMName, MToolkit, etc.) did not solve the problem with Xmonad. I must note that in other window managers (e.g. fluxbox), the app works as expected. In my case, however, I figured out the problem. If you have access to the source of the Java app, I suggest you consider the following:
If you have any JFrame or JPanel or other containers, you should explicitly define their layouts. If you set the layout to null, then the dimensions of the container must be set explicitly. Otherwise, the container won't be rendered at all. For instance, I have a JPanel that contains all my widgets. I'd rather have full control over the layout, so I set the layout to null, and then explicitly set the dimensions for the JPanel:
jContentPane.setLayout(null);
jContentPane.setPreferredSize(new Dimension(appletWidth,appletHeight+100));
Hope this helps.

How do I set an Application's Icon Globally in Swing?

I know I can specify one for each form, or for the root form and then it'll cascade through to all of the children forms, but I'd like to have a way of overriding the default Java Coffee Cup for all forms even those I might forget.
Any suggestions?
You can make the root form (by which I assume you mean JFrame) be your own subclass of JFrame, and put standard functionality in its constructor, such as:
this.setIconImage(STANDARD_ICON);
You can bundle other standard stuff in here too, such as memorizing the frame's window metrics as a user preference, managing splash panes, etc.
Any new frames spawned by this one would also be instances of this JFrame subclass. The only thing you have to remember is to instantiate your subclass, instead of JFrame. I don't think there's any substitute for remembering to do this, but at least now it's a matter of remembering a subclass instead of a setIconImage call (among possibly other features).
There is another way, but its more of a "hack" then a real fix....
If you are distributing the JRE with your Application, you could replace the coffee cup icon resource in the java exe/dll/rt.jar wherever that is with your own icon. It might not be very legit, but it is a possibility...
Also, if you have one "main" window, and set its icon properly, as long as you use that main window as the "parent" for any Dialog classes, they will inherit the icon. Any new Frames need to have the icon set on them, though.
as Paul/Andreas said, subclassing JFrame is going to be your best bet.
Extend the JDialog class (for example name it MyDialog) and set the icon in constructor. Then all dialogs should extend your implementation (MyDialog).

Categories