aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Graphics 2d Object and Scroll Bar Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Graphics 2d Object and Scroll Bar Issue" Watch "Graphics 2d Object and Scroll Bar Issue" New topic
Author

Graphics 2d Object and Scroll Bar Issue

J Cleary
Greenhorn

Joined: Mar 24, 2006
Posts: 13
Hello all, i have a desperate problem please, any ideas would be appreciated.
I want to know how to scroll a screen with a set of rectangles drawn using the java 2d approach (Graphics g)? i have the scroll bar displayed but it does not work.
i have exhausted my ideas.
Thanks
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Here is one example.

Is this what you are looking for?

J Cleary
Greenhorn

Joined: Mar 24, 2006
Posts: 13
Hello, thanks for the reply, i am looking for a normal 2d program approach as opposed to Applets?
i am making a 2d program that creates a visual array of numbers and the array size is larger than the screen so i need to scroll.
J Cleary
Greenhorn

Joined: Mar 24, 2006
Posts: 13
As an example how would i add a scrollbar to the below code please?

package com.javaworld.media.j2d;

import java.awt.*;
import java.awt.event.*;

public class Hear extends Frame {
public static void main(String args[]) {
new Hear();
}

public Hear() {
super("Java 2D Example01");

setSize(400,300);
setVisible(true);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{dispose(); System.exit(0);}
}
);
}

public void paint(Graphics g) {

g.setColor(Color.red);
g.drawRect(50,50,200,200);

Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.blue);
g2d.drawRect(75,75,300,200);
}
}
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

"Learner101"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
In j2se 1.5 the AWT has access to the setPreferredSize method which you can use in lieu of overriding getPreferredSize.
J Cleary
Greenhorn

Joined: Mar 24, 2006
Posts: 13
Thank you Very Very, much my problem is solved!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Graphics 2d Object and Scroll Bar Issue