Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Forced Scroll

Posted on 2001-07-17
10
Medium Priority
?
233 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 400 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

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!

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

721 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