How to set JInternalFrame minimised title background? - java

I can set the title bar background when maximised using InternalFrame.activeTitleBackground and InternalFrame.inactiveTitleBackground but how do I set it when the internal frame is minimised?

There is no easy solution. The frame colors are part of the UI, so you will need to create a custom UI to do what you want. You can start by searching the Java source code to see where the "activeTitleBackground" and "inactiveTitleBackground" properties are used. That will give you an idea of the class and method that needs to be customized.

Related

Java Swing JDialog - how to modify after it is displayed? [duplicate]

I am developing a Java Swing-based application with different perspectives. For the "main menu" perspective I do not want the window (JFrame) to be decorated, while in other perspective I do want the window to be decorated. In other words, I need want to change the decoration attribute dynamically.
I have tried to use setUndecorated(false) and setUndecorated(true), but I seems I can only set this once, before actually showing the window.
Is there a way to achieve this?
From the javadoc:
Disables or enables decorations for this frame. This method can only be called while the frame is not displayable.
Therefore, once the JFrame is packed and/or displayed, you can no longer change that value. If you want to change the undecorated state of a JFrame you will need to dispose() it first, then change the state and eventually make it visible again.
After all, I had to take a different approach.
The former solution did work, as I stated in my last comment.
However, it was showing the default LAF window decoration, while I was using a different LAF.
So the result was graphically inconsistent with the rest of the LAF. Finally, I came with the right solution, I used setUndecorate(true) for my frame. Then, when I had to change my perspective to one using decorations I simply had to use the following code
contentPane.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
And when I had to revert to the non decorate perspective, I use
contentPane.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
This approach didn't need to dispose the window and show it again (which actually produced a brief but still visible hide/show of the window)

Is there any method in java which returns the system's theme color?

I am currently working on a JFrame which is to be set to fullscreen by the user. When in fullscreen, the title bar has to be removed by the JFrame's setUndecorated() method. However doing this deprives the user of the title bar. So I added a JPanel named titleBar at the top which appears only when the cursor is very close to the JFrame's top. Now the problem is that I want the titleBar's color to be the same as the user has set in his System's settings. I have tried to find a method in the System and Toolkit classes but it didn't help. Can anyone tell me if there is a method in java that returns me the current System's title bar color. Any help will be appreciated. Thanks for the attention.
Use UIManager.getColor(key). You have to find the appropriate key for your needs. See this other post for more on the keys:
Swing UIManager.getColor() keys

New window inside a main window?

I am a beginner and I am trying to make a text editor and I want to create a pop up window for text format when I press a menu button where I can put all things like font face, font size , font style etc. Can you tell me how I can make this new window? Thanks for your patience!
For example Notepad:
I think what you're after is a dialog of some kind.
Take a look at How to Make Dialogs for more details.
What I would do is design the basic UI onto a JPanel. I would then add this JPanel to an instance of a JDialog (possibly even using a JOptionPane) and show this dialog, making sure to make it modal, so you can easily retrieve the values set by the user.
This means that you can decide how best to show the user interface or even show it in a number of different ways as it's not constrained to a single top level container
You can simply create a brand spanking new JFrame and it will still be counted as the same application.
Tip: Use Eclipse Window Builder

Dynamically show and hide JFrame decorations

I am developing a Java Swing-based application with different perspectives. For the "main menu" perspective I do not want the window (JFrame) to be decorated, while in other perspective I do want the window to be decorated. In other words, I need want to change the decoration attribute dynamically.
I have tried to use setUndecorated(false) and setUndecorated(true), but I seems I can only set this once, before actually showing the window.
Is there a way to achieve this?
From the javadoc:
Disables or enables decorations for this frame. This method can only be called while the frame is not displayable.
Therefore, once the JFrame is packed and/or displayed, you can no longer change that value. If you want to change the undecorated state of a JFrame you will need to dispose() it first, then change the state and eventually make it visible again.
After all, I had to take a different approach.
The former solution did work, as I stated in my last comment.
However, it was showing the default LAF window decoration, while I was using a different LAF.
So the result was graphically inconsistent with the rest of the LAF. Finally, I came with the right solution, I used setUndecorate(true) for my frame. Then, when I had to change my perspective to one using decorations I simply had to use the following code
contentPane.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
And when I had to revert to the non decorate perspective, I use
contentPane.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
This approach didn't need to dispose the window and show it again (which actually produced a brief but still visible hide/show of the window)

Using standard buttons from a Look and Feel

I am making a UI with Swing, and I want the buttons I am using for my custom dialogs to have the same style as the ones in standard dialogs.
For instance, in the attached image I have a custom dialog and the standard file select dialog. I want the 'OK' and 'Cancel' buttons from the file select dialog to be used for the equivalent buttons in my custom dialog.
I want my application to use the default system look and feel of whatever OS it is running on, so I don't want to try to manually re-create these standard buttons. Using a more rigid Swing class that automatically provides these buttons wouldn't work either, as I'd like to also use them in other, more exotic places in my UI.
Is there an easy solution to this problem?
Sorry to be the bearer of bad news, but it look like there is no standard way to do this cross-platform. The behaviours, mnemonics and icons on default buttons are handled in very specific ways by each look-and-feel.
Here is a SO question that answers the question on how to set the default OK and Cancel buttons on a dialog (the default button is set using getRootPane().setDefaultButton(...) and the Cancel button needs a custom keyboard listener. If you're very lucky, setting the default button might add an icon to it, depending on how the UI is coded.
This forum thread addresses the issue of getting icon resources from the UIManager. Each LaF has a set of UI defaults such as colors, text, borders and icons. There are a number of default icons which are found across all LaFs, but for non-standard icons, such as ones on buttons, there are no guarantees. However, if you tell me which LaF you are using in the screenshot you provided, I can look up the resource keys used by its custom UI classes (or you can find it yourself if you have the source). You could then write a helper method which looks for the icons via these keys, and adds them to the buttons if they are found.
JButton.setUI(ButtonUI) sets the UI for just one JButton. Use that in conjunction with a factory:
public static JButton createStyledButton(String text) {
JButton button = new JButton(text);
button.setUI(STYLE_UI);
return button;
}

Categories