Oben und unten wird über den Bereich des ScrollPane hinaus gemalt, siehe Anhang. Wie kann man das verhindern?
Java:
public class SolutionDisplay {
public void display(int width, int height) {
JFrame frame = new JFrame("Display");
SolutionPanel solutionPanel = new SolutionPanel(width - 100);
JScrollPane scrollPane = new JScrollPane(solutionPanel);
scrollPane.setPreferredSize(new Dimension(width, height));
scrollPane.getVerticalScrollBar().setUnitIncrement(20);
JPanel panel = new JPanel();
panel.add(scrollPane);
frame.add(panel);
frame.setMinimumSize(frame.getSize());
frame.pack();
frame.setVisible(true);
}
private class SolutionPanel extends JPanel {
private SolutionPanel(int panelWidth) {
super();
panelHeight = ...;
generateGraphicComponents();
setPreferredSize(new Dimension(panelWidth, panelHeight));
revalidate();
addMouseMotionListener(new SolutionDisplayMouseMotionListener());
}
public void paintComponent(Graphics g) {...}
}
}