import java.awt.*; import javax.swing.*; public class MyFrame extends JFrame { public MyFrame() { JButton button = new JButton("Click me"); button.setOpaque(true); // make button opaque add(button); setTitle("My frame"); setSize(300, 200); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { new MyFrame(); } }
import java.awt.*; import javax.swing.*; public class MyFrame extends JFrame { public MyFrame() { JButton button = new JButton("Click me"); button.setOpaque(false); // make button transparent add(button); setTitle("My frame"); setSize(300, 200); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { new MyFrame(); } }In this example, we create a JFrame and add a JButton to it. We then call the setOpaque method on the button and pass it the value false to make it transparent. The package library used in this example is java.awt.