Hi Sanjaya,
Hi all,There are many ways to do that. For example you can override the JButton#paintComponent method. Or you can use JLayer, see below: import javax.swing.*; import java.awt.*; public class JLayerSample { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); JButton button = new JButton("Some button"); JLayer<JButton> layer = new JLayer<>(button); JPanel glassPane = new JPanel(new GridBagLayout()); glassPane.add(new JLabel("D3"), new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); layer.setGlassPane(glassPane); glassPane.setOpaque(false); glassPane.setVisible(true); frame.add(layer); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 400); frame.setVisible(true); } }); } } See more about JLayer here: http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html Regards, Pavel |
- <Swing Dev> Adding a label on top of a button Sanjaya Liyanage
- Re: <Swing Dev> Adding a label on top of a but... Pavel Porvatov
- Re: <Swing Dev> Adding a label on top of a but... Walter Laan

