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
Solved

How to write a scrollable JDesktopPane?

Posted on 1998-12-20
6
637 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 56
servlet filter example 37 71
hibernate example using maven 12 57
ejb mdb examples 1 8
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 …
This video teaches viewers about errors in exception handling.

856 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