how to edit jframe title bar? - java

jframe title bar image (run time)
I don't want it undecorated, want black color and change icons.
I am making my college project, I tried making a customized title bar with an undecorated frame, and it works fine, but I have problems dragging the frame and re-sizing it. So I thought maybe I could edit the original frame but didn't find any solutions. Can someone guide me through this?

Assumption : You need a by-default decorated JFrame, which acquires the look & feel of the machine's operating system.
Setting an icon and customizing text on Title bar is easy.It can be done as shown below,
class TitleBar {
TitleBar(){
Frame f=new Frame();
//Setting TitleBar icon with "YourImage.png"
f.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("YourImage.png")));
//set other parameters as per your choice viz size layout etc.
//Set the Title Bar text
f.setTitle("YOUR CUSTOM TEXT");
f.setVisible(true);
}
Now with the frame decoration turned "ON", it is not possible to change the color of titlebar, font of the top-level JFrame (to the best of my knowledge). You CAN change the color of an InternalFrame however.
If you want to customise these then turn off windows decorations with f.setUndecorated(true) and you can change the title bar appearance with the help of LAF (Look And Feel). This is better explained in the answer below :
Change the color of the title bar in javax.swing
You may also try modifying the UIDefaults as shown here :
Modifying UIDefaults | For Windows 10 and above
Do upvote if my answer is useful !!

Related

How to change the default JFrame Window color?

I am building an app for Windows using Java Swing/AWT interfaces in IntelliJ Idea. I am using a default JFrame to display my application GUI. However, I would like to change the default frame outline (window) colour to either transparent or custom colour.
Here is what I am trying to achieve:
This is the window I have:
These two are the ones I am trying to achieve (transparency or custom colours):
Or this
Is there a way to achieve this?
You can use custom title bar by creating a new panel and set undecorated on your frame to hide default title bar
add your title to the new panel and buttons (exit, minimize...)
Frame.setUndecorated(true);

Create translucent and blurred components in java

I need to create a panel which is partially transparent and which blurs what appears behind the panel. Such as the title bar in widows 7. Help me if someone knows how to do this very simply

How can I let Metal give all option dialogs the same title bar color as JFrame's when using it's window decorations?

I use
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
to have windows use the window decorations of Metal.
Metal has a title bar color for different types of JOptionPane's. Nice feature, but for this case it's annoying.
How can I let Metal give all option dialogs the same title bar color as JFrame's?

Can you put JFrames inside Full Screen Exclusive Mode?

To be honest, I didn't quite know how to express my question in the title. So if someone has a clearer idea of what i'm trying to ask, then please be so kind as to edit it, for the greater good of mankind.
I have the following code:
public class Main {
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
JFrame frame = new JFrame();
Window window = new Window(frame);
JButton btn = new JButton("Quit");
window.add(btn);
if(gd.isFullScreenSupported())
gd.setFullScreenWindow(window);
btn.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
gd.setFullScreenWindow(null);
}
});
}
}
What I want to do is make a library system, illustrated in full screen mode. Inside the full screen mode, there should be simple frame windows with text fields in them and so on... No heavy 2D/3D graphics required here...
My problem is, the quit button is resized to fit the entire screen. I've tried to use setBounds, setSize, etc, on the frame, window and even button... But it doesn't seem to let me be able to center the button in the middle.
So my question: Is it possible to make JFrame application windows inside a JFrame application window which is set to full screen exclusive mode? Or is it only possible to use full screen exclusive mode together with 2D/3D methods like drawing?
Note: The only thing I intend to use full screen mode for is to set it to a black background, and have a Jframe window ontop of this black background in the center of the application. It is to give the illusion that the application is actually a system.
Thank you.
P.S. please note that the quit button was merely for my own testing purposes. It won't be part of the actual system, so my question does not revolve around how to resize this particular quit button.
Fullscreen Exclusive Mode is not meant to have Swing components inside. It is meant as a high performance way to draw graphics in Java (and can benefit as much as possible of underlaying hardware if done right).
What you want to do could be done by using an undecorated JDesktopPane and maximize it over the dimensions of the screen. Then proceed with using a JInternalFrame to have a JFrame like window inside that JDesktopPane.
I've included links to the respective API sections, they should get you started.
I think that what you are after is an MDI Application. If that is what you are after you could take a look here.
Your problem is that you do not use layout manager correctly.
Learn about layout managers - the modules that put and size/resize the visual components on screen. Then decide how do you want your button to look like and then decide which layout manager to use. It will do its job.
You know what i also had the exact same problem and the only thing i know from my experience is that you can use jinternal frame and set its property undecorated to true then add your custom title bar according to your requirement.

Internal JFrame Properties

I have a JInternalFrame as shown below.
Are there properties that allow for?
coloring
hiding the title bar
adding text
Further Customization*
to the top bar?
The only thing I have been able to find is:
jInternalFrame1.setTitle("Hello");
But I am more after a way to hide it etc.
you can set through it's constructor like button maximize, minimize, resize, icon etc
and http://www.roseindia.net/answers/viewqa/Java-Beginners/1923-Hide/remove-titlebar-of-JInternalframe.html
another example with multiple JInternalFrame
To remove all the decorations from the title bar you can create a smaller bar (in height) that will only allow the user to drag the internal frame:
frame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
To remove the title bar when using the Metal LAF you can use something like:
BasicInternalFrameUI ui = (BasicInternalFrameUI)frame.getUI();
Component north = ui.getNorthPane();
north.setPreferredSize( new Dimension(0, 0) );
north.validate();

Categories

Resources