简体   繁体   中英

making JFrame with custom texture

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:

在此处输入图片说明

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

You should try JavaFX to create awesome window on java.

http://www.oracle.com/technetwork/java/javafx/samples/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM