【发布时间】:2014-01-12 15:47:10
【问题描述】:
有什么办法可以把 JLabel 放在矩形前面吗?目前,JLabel 位于矩形下方。
这是我的相关代码:
public class MainMenu_South extends JPanel {
MainMenu_BlueJay t;
JLabel start=new JLabel("START");
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.blue);
g2d.drawRect(0, 30, 900, 30);
g2d.fillRect(0, 30, 900, 30);
}
public MainMenu_South(MainMenu_BlueJay t){
setLayout(null);
this.t=t;
setBackground(Color.white);
start.setForeground(Color.red);
start.setFont(new Font("Arial", Font.BOLD, 16));
add(start);
start.setBounds(100, 10, 100, 50);
start.addMouseListener(ml);
}
MouseListener ml=new MouseListener() {
@Override
public void mouseEntered(MouseEvent e) {//hover
start.setForeground(Color.white);
}
@Override
public void mouseExited(MouseEvent e) {
start.setForeground(Color.red);
}
};
}
【问题讨论】:
-
阅读swing tag wiki中引用的绘画文章:-)
-
你知道为什么这个问题没有得到回答
标签: java swing panel graphics2d