在玻璃板上放置部件
package test;import java.awt.Color;import javax.swing.JFrame;
import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.border.LineBorder;public class MainFrame extends JFrame {
/**
* @param args
*/
public static void main(String[] args) {
MainFrame mf = new MainFrame();
mf.setSize(400, 400);
mf.setLocationRelativeTo(null);
mf.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
mf.setGlassPane(new JPanel());
JLabel l = new JLabel();
l.setText("Hello");
l.setBorder(new LineBorder(Color.BLACK, 1));
l.setBounds(10, 10, 50, 20);
l.setBackground(Color.RED);
l.setOpaque(true);
l.setPreferredSize(l.getSize());
//mf.add(l);
((JPanel)mf.getGlassPane()).add(l);
mf.getGlassPane().setVisible(true);
mf.setVisible(true);
}}
慕沐林林
Smart猫小萌
随时随地看视频慕课网APP
相关分类