Solved

Forced Scroll

Posted on 2001-07-17
10
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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!

 
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

Independent Software Vendors: 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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

734 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