I am using Applet to display the Bar Graph.
The Applet size is width=500 & height=500.
I used canvas to display the graph & added to Container ScrollPane for scrolling.
I was able to get scrollbars .
But the problem is ---
If I input more bars to draw(exceeds the width 500), it's not Showing up all the graphs. The bars are visible up to some extent.I want the Width of the Applet not to vary.
I used setsize() & validate()
What shall I do for this?
I want the solution in AWT. I am not using
Swings
The code is
--------------
import java.awt.*;
import java.applet.*;
import java.util.*;
public class RetirePlanBar extends Applet
{
public Vector vec;
public RetirePlanCanvas mc = null;
private ScrollPane sp;
public String t1;
public void init()
{
vec = new Vector();
for(int i=0; i<9; i++)
{
add("1",300,200);
add("2",500,200);
add("3",800,200);
add("4",1234,200);
add("5",5000,200);
add("6",99999,200);
add("7",5000,200);
add("8",99999,200);
}
mc = new RetirePlanCanvas(this);
sp = new ScrollPane(0);
sp.add(mc);
sp.setVisible(true);
setLayout(new GridLayout(1,0));
add(sp);
validate();
// this.setSize(1000,500);
// this.setSize(500,500);
}
public void render()
{
repaint();
mc.repaint();
}
public void paint(Graphics g)
{
int w =getSize().width;
int h = getSize().height;
g.setColor(Color.white);
g.fillRect(0,0,w,h);
}
public void add(String name,int value,int r)
{
Integer val = new Integer(value);
Color cc = new Color(r);
Vector row = new Vector();
row.addElement(name);
row.addElement(val);
row.addElement(cc);
vec.addElement(row);
}
}
by: omry_yPosted on 2000-10-21 at 06:10:48ID: 4838619
after you change the size of your canvas, you need to call validate on the panel which contains your scrollPane, not on the canvas.