• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graphics 2d Object and Scroll Bar Issue

 
J Cleary
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is one example.

Is this what you are looking for?

 
J Cleary
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In j2se 1.5 the AWT has access to the setPreferredSize method which you can use in lieu of overriding getPreferredSize.
 
J Cleary
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Very Very, much my problem is solved!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic