[英]How to add JButton to Canvas()? Or how to add JButton to Panel() and make the Panel() background as transparent?
如何将JButton
添加到我的Canvas
?
public class mywindow extends Window
{
private static final Canvas canvas = new Canvas();
private JButton button;
public mywindow
{
super(new Frame());
button = new JButton("close");
setLayout (new BorderLayout ());
//Step 1 - failed
add("North", canvas);
canvas.setSize(300,300);
canvas.setLocation(0,0);
// button = new JButton(my, "close"); will not work
// How can I add the button to the canvas?
//Step 2 - works, but it gets the background color, instead of real transparency.
//JPanel p = new JPanel(); p.setOpaque(false);
//p.setSize(300,300); p.setLocation(0,0);
//add("North", p);
//p.add("Left", button);
}
}
请不要将AWT与Swing混合使用。 今天,需要JPanel的 Swing 代码。 当然,可以将 AWT 与 Swing 但意外的 output 混合到 GUI。 对于透明度,您必须查看如何创建半透明和形状 Windows并在此处搜索示例。
编辑:为了最好和更好的 output 到 GUI 检查, LayoutManagers是如何工作的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.