The Artima Developer Community
Sponsored Link

Java Answers Forum
is it possible to add JScrollPane/Bar to JPanel and painting

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

is it possible to add JScrollPane/Bar to JPanel and painting Posted: Nov 15, 2006 12:23 PM
Reply to this message Reply
Advertisement
I hav added a JScrollpane to JPanel and the JPanel is added to a JFrame.Then i painted/drawn some rectangles using paintComponet().There r many rectangles drawn but I cant scroll down the JPanel. Is it possible to scroll down a JPanel to see all paintings down this area where some paintings hav been made during runtime.And what if I want to change the color of each rectangle during runtime. I also want to add a button which being pressed will do all this drawing on the JPanel. Or is there any component to draw this way.I hav given the code I hav tried my best, Pls help me, actually I m trying to make a GantChart.
import java.awt.*;
import javax.swing.*;
 
public class drawGraph extends JPanel {
JFrame frm=new JFrame();
JScrollPane sPane=new JScrollPane();
JButton b=new JButton();
 
public drawGraph() {
 
this.setBorder(BorderFactory.createLineBorder(Color.red,3));
this.setBackground(Color.darkGray);
this.setBounds(90,290,100,100);
frm.getContentPane().add(sPane,BorderLayout.CENTER);
b.setBounds(30,30,90,190);
sPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
sPane.getViewport().add(this);
//sPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
frm.setSize(new Dimension(800, 600));
Toolkit tk=Toolkit.getDefaultToolkit();
Dimension d=tk.getScreenSize();
frm.setLocation((d.width-800)/2,(d.height-600)/2);
frm.setVisible(true);
  }
 
public void paintComponent(Graphics g){
  super.paintComponent(g);
   int width=15;
        int hight=12;
        int down=60;
        int strX=140;
        int lineX=140;
       //double cval;
        int cR,cG,cB;
        //cval=Math.random();
 
 
///////////////////////////FOR DATE TITLE/////////////////////////
        for( int i=1; i<32 ; i++ )
        {
        g.setColor(Color.red);
        String st=new String().valueOf(i);
        g.setFont(new Font("Monospaced",Font.BOLD+Font.ITALIC,13));
        g.drawString(st,strX,45);
        g.setColor(Color.magenta);
        strX=strX+22;
 
        }
         for( int i=1; i<50 ; i++ )
        {  g.drawLine(lineX,37,lineX,1000);
           lineX=lineX+20;
        }
//////////////////////////FOR BAR CHART/TIMELINE/////////////////////////
 
    for(     int a=1; a<60 ; a++      ){
                cR=160;
                cG=46;
                cB=98;
                g.setColor(new Color(cR,cG,cB));
		g.fill3DRect(140,down,width,hight,true);
           	down=down+20;
                width=width+20;
                cR=cR+15;
                cG=cG+5;
                cB=cB+35;
        }
  }
 
 
 
 
  public static void main(String[] args) {
    drawGraph dGraph = new drawGraph();
    }
} 
Pls Help me ,u hav always been so helpful.THNX

Topic: is it possible to add JScrollPane/Bar to JPanel and painting Previous Topic   Next Topic Topic: -Xrunjcov option

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use