Solved

How to write a scrollable JDesktopPane?

Posted on 1998-12-20
6
622 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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.

914 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

22 Experts available now in Live!

Get 1:1 Help Now