Solved

How to write a scrollable JDesktopPane?

Posted on 1998-12-20
6
617 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

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

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 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 …
The viewer will learn how to implement Singleton Design Pattern in Java.

762 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

21 Experts available now in Live!

Get 1:1 Help Now