6
我有这个代码使图标图像Jbutton,它的工作原理。但问题是,按钮的边框和背景不会消失。如何隐藏JButton的背景(哪个containt图标图像)?
我只想要图标图像出现无边框&按钮的背景。
我试图设置setOpaque(false)
,但是所有按钮都消失了!
我的代码有什么问题?
_button = new JButton("Exit");
_button.setHorizontalTextPosition(SwingConstants.CENTER);
_button.setSize(200,130);
//_button.setContentAreaFilled(false);
_button.setBorderPainted(false);
//_button.setOpaque(false);
_button.setIgnoreRepaint(true);
//_button.setFocusable(false);
_button.setIcon(button_icon);
_button.setBounds(200, 200,200, 170);
_button.setRolloverEnabled(true);
_button.setRolloverIcon(button_icon_hover);
_button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
//_button.addActionListener(this);
_button.setBackground(null);
_button.setFocusable(true);
_button.setFocusPainted(true);
_button.setForeground(Color.WHITE);
_button.setFont(new Font("Times New Roman",Font.BOLD,35));
我用这个代码,但边框和背景都消失的问题是图像无法点击 – alex
这是工作部分。 –
@SanjitKumarMishra你为什么说部分? –