怎么让jframe组件透明
privatevoidinitialize(){/***initializethemainjframe*/frame=newJFrame();frame.setResiz...
private void initialize() { /** * initialize the main jframe */
frame = new JFrame();
frame.setResizable(false);
frame.setBounds(350, 10, 1000, 800); /** * parameter main panel */
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
deadwoodListSize = new JTextField();
deadwoodListSize.setBounds(0, 0, 100, 100); /** * parameter left hand side text panel */
deadwoodPanel = new JPanel(null);
deadwoodPanel.setBounds(20, 240, 350, 190); /** * parameter right hand side text panel */
deadwoodPanel.add(deadwoodListSize);
frame.getContentPane().add(deadwoodPanel);
frame.setUndecorated(true);
consoleTextArea = new JTextArea();
consoleTextArea.setBounds(0, 20, 400, 190); /** * parameter text area */
consoleTextArea.setWrapStyleWord(true);
consoleTextScrollPane = new JScrollPane(consoleTextArea);
consoleTextScrollPane.setBounds(370, 240, 400, 190); /** * parameter text area */
frame.getContentPane().add(consoleTextScrollPane);
computerPanel = ComputerPanel.getInstance();
frame.getContentPane().add(computerPanel);
buttonPanel = new JPanel(null);
buttonPanel.setBounds(780, 20, 70, 200); /** * parameter of start and quit button */ 展开
frame = new JFrame();
frame.setResizable(false);
frame.setBounds(350, 10, 1000, 800); /** * parameter main panel */
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
deadwoodListSize = new JTextField();
deadwoodListSize.setBounds(0, 0, 100, 100); /** * parameter left hand side text panel */
deadwoodPanel = new JPanel(null);
deadwoodPanel.setBounds(20, 240, 350, 190); /** * parameter right hand side text panel */
deadwoodPanel.add(deadwoodListSize);
frame.getContentPane().add(deadwoodPanel);
frame.setUndecorated(true);
consoleTextArea = new JTextArea();
consoleTextArea.setBounds(0, 20, 400, 190); /** * parameter text area */
consoleTextArea.setWrapStyleWord(true);
consoleTextScrollPane = new JScrollPane(consoleTextArea);
consoleTextScrollPane.setBounds(370, 240, 400, 190); /** * parameter text area */
frame.getContentPane().add(consoleTextScrollPane);
computerPanel = ComputerPanel.getInstance();
frame.getContentPane().add(computerPanel);
buttonPanel = new JPanel(null);
buttonPanel.setBounds(780, 20, 70, 200); /** * parameter of start and quit button */ 展开
1个回答
展开全部
frame.setUndecorated(true);
jdk1.6:后面加com.sun.awt.AWTUtilities.setWindowOpaque(frame, false);
jdk1.7:有frame.setOpacity(透明度);和frame.setShape(形状);可以使用
jdk1.6:后面加com.sun.awt.AWTUtilities.setWindowOpaque(frame, false);
jdk1.7:有frame.setOpacity(透明度);和frame.setShape(形状);可以使用
更多追问追答
追问
我用了frame.setUndecorated(true); , 它把我的程序的最外面的边框去掉了,而不是去掉组件的边框
追答
我是让你在那句话后面加我写的那句话,如果你的jdk版本是1.7以下,这样写:
frame.setUndecorated(true);
com.sun.awt.AWTUtilities.setWindowOpaque(frame, false);
如果你的jdk版本是1.7或1.8,这样写:
frame.setUndecorated(true);
frame.setOpacity(0.0f);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询