Reputation: 14108
How to set a custom window's frame header?
Instead of this blue header I want to use a texture from image.
code:
final JFrame frame = new JFrame();
BufferedImage image = ImageIO.read(new File("d:/texture.bmp"));
default window:
Upvotes: 0
Views: 1735
Reputation: 1017
I do not think that you can do anything about the colors or images in the title bar of a JFrame, at least not without using native code to implement a platform-specific solution. That is because JFrame actually uses your native windowing system to create the window.
As for internal frames, it would make sense for you to be able to customize it, since it is a component rendered inside of a window that is controlled by Java. Indeed, there are plenty of JInternalFrame properties that you can set in your UI manager.
You cannot place an image over there. However you can try JavaFX.
Here is something i did by trying out looks and feel :
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
public class TitleColor
{
public static void main_helper (String args[])
{
JFrame f = new JFrame ();
f.setDefaultCloseOperation
(
JFrame.DISPOSE_ON_CLOSE
);
f.setSize (300, 300);
f.setLocationRelativeTo (null);
f.setUndecorated ( true );
f.getRootPane ().setWindowDecorationStyle
(
JRootPane.FRAME
);
JPanel panel = new JPanel ();
panel.setBackground ( java.awt.Color.white );
f.setContentPane ( panel );
DefaultMetalTheme z =
new DefaultMetalTheme ()
{
//inactive title color
public ColorUIResource
getWindowTitleInactiveBackground()
{
return new ColorUIResource
(java.awt.Color.orange);
}
//active title color
public ColorUIResource
getWindowTitleBackground()
{
return new ColorUIResource
(java.awt.Color.orange);
}
//start ActiveBumps
public ColorUIResource
getPrimaryControlHighlight()
{
return new ColorUIResource
(java.awt.Color.orange);
}
public ColorUIResource
getPrimaryControlDarkShadow()
{
return new ColorUIResource
(java.awt.Color.orange);
}
public ColorUIResource
getPrimaryControl()
{
return new ColorUIResource
(java.awt.Color.orange);
}
//end ActiveBumps
//start inActiveBumps
public ColorUIResource
getControlHighlight ()
{
return new ColorUIResource
(java.awt.Color.orange);
}
public ColorUIResource
getControlDarkShadow ()
{
return new ColorUIResource
(java.awt.Color.orange);
}
public ColorUIResource
getControl ()
{
return new ColorUIResource
(java.awt.Color.orange);
}
//end inActiveBumps
};
MetalLookAndFeel.setCurrentTheme
(
z
);
try
{
UIManager.setLookAndFeel
(
new MetalLookAndFeel ()
);
}
catch (Exception e)
{
e.printStackTrace ();
}
SwingUtilities.updateComponentTreeUI (f);
f.setVisible (true);
}
public static void main (final String args[])
{
SwingUtilities.invokeLater
(
new Runnable ()
{
public void run ()
{
main_helper ( args );
}
}
);
}
}
Upvotes: 3
Reputation: 48
You should try JavaFX to create awesome window on java.
http://www.oracle.com/technetwork/java/javafx/samples/index.html
Upvotes: 1