• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Graphics 2d Object and Scroll Bar Issue

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Very Very, much my problem is solved!!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic