Solved

Forced Scroll

Posted on 2001-07-17
10
222 Views
Last Modified: 2008-03-03
I have a scrollpane that I need to reposition. I have tried to change the value of the Vertical scrollbar but this was unsuccessful. This is a sample of the code that I used.
getOESScrollPane().getVerticalScrollBar().setValue(2);

Thanks in advance for your help
0
Comment
Question by:xaun
10 Comments
 
LVL 4

Accepted Solution

by:
sdussinger earned 100 total points
ID: 6291236
Try this:

Point pos = getOESScrollPane().getViewport ().getViewPosition ();

pos.y -= 50;

getOESScrollPane().getViewport ().setViewPosition (pos);

This will scroll the viewport vertically by 50 pixels.

--Steve
0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6291243
Try this:

Point pos = getOESScrollPane().getViewport ().getViewPosition ();

pos.y -= 50;

getOESScrollPane().getViewport ().setViewPosition (pos);

This will scroll the viewport vertically by 50 pixels.

--Steve
0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6291245
Try this:

Point pos = getOESScrollPane().getViewport ().getViewPosition ();

pos.y -= 50;

getOESScrollPane().getViewport ().setViewPosition (pos);

This will scroll the viewport vertically by 50 pixels.

--Steve
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:sdussinger
ID: 6291249
Sorry. It seems that refreshing this page after generating a response causes the response to be posted more than once.

Guess I won't do that again!!

--Steve
0
 

Author Comment

by:xaun
ID: 6294282
Thanks for your input Steve but that solution didn't work. I tried it once before I posted the question then again after your suggestion.
0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6294943
That's odd. I tested it on my machine and it works fine.

I've included the test program that I used. If you have a slow internet connection, it'll take a while to load since its grabbing an image to scroll, so be patient.

Can you post your code here, so we can try and figure out why it fails for you?

Here's the code:

----------------------------------------------------------
public class JFrame extends javax.swing.JFrame
{

    public JFrame()
    {
        initComponents ();
        pack ();
    }

    private void initComponents()
    {
        jScrollPane1 = new javax.swing.JScrollPane();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        addWindowListener(new java.awt.event.WindowAdapter()
         {
          public void windowClosing(java.awt.event.WindowEvent evt)
          {
              exitForm(evt);
          }
         }
                 );
       
       
     try
         {
          java.net.URL url = new java.net.URL ("http://thebishop.ne.mediaone.net/photos/images/DSCN0159.JPG");

          jLabel1.setIcon(new javax.swing.ImageIcon(url));
         }
     catch (Exception e)
         {
         }

     jLabel1.setText("jLabel1");
     jScrollPane1.setViewportView(jLabel1);
           
        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
         
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButton1ActionPerformed(evt);
          }
         } );
       
        getContentPane().add(jButton1, java.awt.BorderLayout.SOUTH);
       
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
    {
     java.awt.Point pt = jScrollPane1.getViewport().getViewPosition ();
     
     System.out.println (pt);
     
     pt.y -= 50;
     
     jScrollPane1.getViewport ().setViewPosition (pt);
    }

    private void exitForm(java.awt.event.WindowEvent evt)
    {
     System.exit (0);
    }

    public static void main (String args[])
    {
        new JFrame ().show ();
    }


    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton jButton1;

}

----------------------------------------------------------

--Steve
0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6294948
Whenever you click on the button at the bottom of the panel, the image will scroll down by 50 pixels.

--Steve
0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6382880
Did this work for you? Are you planning on closing this question?

--Steve
0
 
LVL 5

Expert Comment

by:vemul
ID: 7669700
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- points to sdussinger
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7714875
Per recommendation, force-accepted.

Netminder
EE Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java basic valueOf question 1 32
web project error add remove 1 49
passing enum to a method 4 34
activeMQ Queue Messages Enqueued and Messages Dequeued 1 24
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question