class Glass extends JComponent { JLabel label; public Glass(JButton butt, JLabel label, RootPaneContainer parent) { this.label = label; this.addMouseListener(new ButtonMouseListener(this, parent.getContentPane(), butt)); } public void paintComponent(Graphics g) { Rectangle rect = label.getBounds(); int x = rect.x + rect.width / 2; Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(0.5f, 0.5f, 0.5f, 0.8f)); g2d.fillRect(x, rect.y, rect.width / 2, rect.height); } }