Solved

How to write a scrollable JDesktopPane?

Posted on 1998-12-20
6
665 Views
Last Modified: 2008-03-10
I implemented the Scrollable interface in my class,then I create a JScrollPane of it, but it is still not scrollable.
Code examples is welcomed. Thank you!
0
Comment
Question by:f22
[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
  • 4
  • 2
6 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229824
you want to create scorllable JDesktopPane, (so that when some internal frames get out of the screen JDesktopPane adds scrollers to itself) or ?
0
 

Author Comment

by:f22
ID: 1229825
Yes, that's what I want. But I have solve this problem. I have another question, is it possible to create graphical components of arbitrary shape? What I want is to a line shape. I need to display a lot of lines in the panel and each line is an object so I can click on them, for example. But if I use Canvas, I'm afraid the rectangle shape of canvas will cause the lines block each other.
Thank you for your attention. I will pass the points to you if you'd like to give comments on this problem.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229826
check this question (and my comments there) - it is open. maybe this is what you want - i don't know.
http://www.experts-exchange.com/topics/comp/lang/java/Q.10110666

can you (please :) post some (little) working example about scrollable JDesktopPane? this question was discussed a long ago at DukeDollars forum (Javasoft web site) and there was partially solution there (i was going to give you the URL when you define more precisely your question:))

merry christmas
  heyhey
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:f22
ID: 1229827
Thank you for your comment! I solve the problem by using setPreferedSize of the JDesktopPane.

import java.applet.Applet;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class WorkPane extends JDesktopPane implements Scrollable, MouseMotionListener{
      public WorkPane(){
            setLayout(null);
            setPreferredSize(new Dimension(1000,1000));
            addMouseMotionListener(this);
      }
      

    public Dimension getPreferredScrollableViewportSize() {
        return getPreferredSize();
    }

    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {

        int currentPosition = 0;
        if (orientation == SwingConstants.HORIZONTAL)
            currentPosition = visibleRect.x;
        else
            currentPosition = visibleRect.y;

        if (direction < 0) {
            int newPosition = currentPosition - (currentPosition / maxUnitIncrement) * maxUnitIncrement;
            return (newPosition == 0) ? maxUnitIncrement : newPosition;
        } else {
            return ((currentPosition / maxUnitIncrement) + 1) * maxUnitIncrement - currentPosition;
        }
    }

    public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
        if (orientation == SwingConstants.HORIZONTAL)
            return visibleRect.width - maxUnitIncrement;
        else
            return visibleRect.height - maxUnitIncrement;
    }

    public boolean getScrollableTracksViewportWidth() {
        return false;
    }

    public boolean getScrollableTracksViewportHeight() {
        return false;
    }
  }

then I use a JScrollPane to display it.
Please post an anwser so that I can pass you the points.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229828
a haven't helped you so much :)
if you want, you can delete the question and get back your points.
if you think that i've really helped you, then i'll post an answer.
0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
ID: 1229829
ok, than I'm posting an <empty answer>

thanks
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
This video teaches viewers about errors in exception handling.
Suggested Courses

623 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