所以我可以尝试问我的问题,但为了你和我的缘故,我在photoshop中创建了一个简单的图像,试图告诉你我想要实现的目标:
我曾尝试使用AWTUtilities中的Opaque东西,但它似乎不起作用你们有任何想法我怎么能实现这个?
我确实需要本机窗口边框,因此我可以拖放窗口,还需要调整大小功能。
提前致谢
答案 0 :(得分:1)
对于透明/跨度JFrame
,请参阅此处:http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html,它解释了Java中的半透明Windows。
您需要致电setOpacity()
。
这也是一个小例子:
import java.awt.*;
import javax.swing.*;
import static java.awt.GraphicsDevice.WindowTranslucency.*;
public class TranslucentWindowDemo extends JFrame {
public TranslucentWindowDemo() {
super("TranslucentWindow");
setLayout(new GridBagLayout());
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add a sample button.
add(new JButton("I am a Button"));
}
public static void main(String[] args) {
// Determine if the GraphicsDevice supports translucency.
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
//If translucent windows aren't supported, exit.
if (!gd.isWindowTranslucencySupported(TRANSLUCENT)) {
System.err.println(
"Translucency is not supported");
System.exit(0);
}
JFrame.setDefaultLookAndFeelDecorated(true);
// Create the GUI on the event-dispatching thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
TranslucentWindowDemo tw = new TranslucentWindowDemo();
// Set the window to 55% opaque (45% translucent).
tw.setOpacity(0.55f);
// Display the window.
tw.setVisible(true);
}
});
}
}