My Canvas is on Top of My Scroller
Hi, I've been trying to right the code for a function grapher in netBeans.
I have the grapher class which extends java.awt.Canvas and draws a coordinate plane using its paint method. This grapher class is placed inside a scrollerPane with the following code:
graphScroller =new javax.swing.JScrollPane();
graph =new Grapher(width, height);
graphScroller.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
graphScroller.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
graphScroller.setViewportView(graph);
org.jdesktop.layout.GroupLayout graphPanelLayout =new org.jdesktop.layout.GroupLayout(graphPanel);
graphPanel.setLayout(graphPanelLayout);
graphPanelLayout.setHorizontalGroup(
graphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(graphScroller, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 684, Short.MAX_VALUE)
);
graphPanelLayout.setVerticalGroup(
graphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(graphScroller, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
);
Whenever the size of the grapher is less than the scroller everything works fine, but when, for instance, the width is greater than the width of the scroller, the grapher extends past and covers up anything else in the program. It does, however, move back and forth whenever the scrollbar is moved. Is there some way to set like a z-index or something so that it is behind all the other elements? Thanks.

