Java: Remove title bar buttons only - java

I've only found ways to completely remove title bar + borders. I want to create a window in Swing without title bar buttons but still retain the default system's border. Is this possible?

The following link has a complete working example that uses remove() on the buttons:
http://www.coderanch.com/t/344419/GUI/java/deactivate-close-minimise-resizable-window

You can use the frame's setUndecorated() method and render your own decorations. You may want to leverage the JInternalFrame UI defaults, which typically recapitulate those of the platform's default Look & Feel, as shown here. These seem especially relevant:
InternalFrame.activeTitleBackground
InternalFrame.activeTitleForeground
InternalFrame.inactiveTitleBackground
InternalFrame.inactiveTitleForeground

Related

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

How do I change the tooltip look and feel to the system's?

I have added the line to set look and feel to system. This is found to work because the scroll bars have changed.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
But when I set a tooltip to my JTabbedPane's tab, it does not show the system's look and feel for tooltips. Why is this? Screenshots are below.
System's look and feel:
Java's look and feel(?):
I want to set my tooltip to look like the system's which is in the first screenshot. How do I do this?
Much work without the complete effect:
for getting the background you need a custom implemenation of ToolTipUI: basically extend BasicToolTipUI and take over the painting
register the custom ui delegate with the UIManager so that it is used instead of the default
theoretically, you can achieve the rounded corners of the window (the one containing the tooltip) by using a shaped window (public api in jdk7, a half-official workaround available for jdk6), you would need a shaped window. Practically, there is no way (except extreme hacking) to make the ToolTipManager use that window

java titlebar modification

I'd like to change the color of the java titlebar and add some text to the ends and the middle.
The previous coder used setUndecorated(false) and a JPanel to achieve this effect but I am trying to change this to modify the actual title bar because the panel solution is an issue with menus and focus.
tl;dr Want to change the color of the titlebar and set text in the middle and one the ends.
I think you can change the title bar color with the method described here: http://www.coderanch.com/t/346141/GUI/java/set-JFrame-titlebar-color
Changing the text should be possible via setTitle(). You can call this method as many times as you want throughout the life of the application to change the title text on the fly.

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;
}

How to set JInternalFrame minimised title background?

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.

Categories