posted 18 years ago
Ilja,
I wasn't able to get your suggestion to work. My program consists of a custom JPanel called DrawingPanel. I wrap the DrawingPanel in a JScrollPane then add the DrawingPanelto my JPanel window.
I want the user to press a "MoreData" button to update the date in the window. I used the following (see jButtonMoreDataActionPerformed below), but it didn't work. Where did I go wrong?
//..... Button to get a new set of data and reset the window
private void jButtonMoreDataActionPerformed( ActionEvent evt ){
Rectangle visible = jScrollPane.getVisibleRect();
jScrollPane.scrollRectToVisible( visible );
}
// CODE FRAGMENTS TO SHOW THE SETUP OF THE WINDOW
// Create a custom JPanel to draw on
DrawingPanel drawingPanel= new DrawingPanel();
// Add the custom JPanel to a JScrollPane
JScrollPane jScrollPane = new JScrollPane( drawingPanel );
// Add the widgets to the page
JPanel jPanel = new JPanel();
SpringLayout springLayout = new SpringLayout();
jPanel.setLayout(springLayout);
// Add the scroll pane to the page
jPanel.add( jScrollPane );
// Lay out the buttons in one row and as many columns
// as necessary, with 6 pixels of padding all around.
SpringUtilities.makeCompactGrid(
jPanel, // Container
1, 2, // rows, cols
0, 0, // initialX, initialY,
0, 0); // xPad, yPad
// Add the spring layout to the grid bag
// code here
// Custom inner class
public class DrawingPanel extends javax.swing.JPanel
{
public void paintComponent(Graphics g){
super.paintComponent(g);
// stuff
}
}
Thank you for your help,
Ed