Transparent JButton

后端 未结 2 398
旧巷少年郎
旧巷少年郎 2020-11-29 00:37

Is it possible to make a JButton transparent (including the border) but not the text? I extend swing\'s JButton and override this:

@Override
public void pain         


        
相关标签:
2条回答
  • 2020-11-29 01:09

    The following should do the trick.

    public class PlainJButton extends JButton {
    
        public PlainJButton (String text){
            super(text);
            setBorder(null);
            setBorderPainted(false);
            setContentAreaFilled(false);
            setOpaque(false);
        }
    
        // sample test method
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            JPanel pane = new JPanel();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pane.add(new PlainJButton("HI!!!!"));
            frame.add(pane);
            frame.pack();
            frame.setVisible(true);
        }
    }
    
    0 讨论(0)
  • 2020-11-29 01:22
    button.setOpaque(false);
    button.setContentAreaFilled(false);
    button.setBorderPainted(false);
    
    0 讨论(0)
提交回复
热议问题