Java tutorial
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; public class Main { public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new BorderLayout()); f.add(new TestPane()); f.pack(); f.setVisible(true); } } class TestPane extends JPanel { public TestPane() { setLayout(new BorderLayout()); JPanel top = new JPanel(new GridBagLayout()); top.setOpaque(false); top.add(new JLabel("OK")); JScrollPane sp = new JScrollPane(); sp.setOpaque(false); sp.getViewport().setOpaque(false); sp.setViewportView(top); add(sp); } @Override public Dimension getPreferredSize() { return new Dimension(200, 200); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED); g2d.drawLine(0, 0, getWidth(), getHeight()); g2d.drawLine(getWidth(), 0, 0, getHeight()); g2d.dispose(); } }