Solved

Forced Scroll

Posted on 2001-07-17
10
194 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now