Results 1 to 1 of 1
Thread: problem with scroll bar
- 04-22-2009, 01:24 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 2
- Rep Power
- 0
problem with scroll bar
hello all,
Can anybody tell me how to activate a scrollbar for a jpanel. I have drawn 15 rectangles using paint method.My code goes here..
Please anybody help me with the scroll bar problem.how and when to use repaint().I am new to swing and applets.:confused:.Help me.Java Code://start of the class// super(new BorderLayout()); Dimension d=new Dimension(800,800); drawpane.setBackground(Color.LIGHT_GRAY);//JPanel drawpane drawpane.setPreferredSize(d); JScrollPane scroller = new JScrollPane(drawpane,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroller.setBackground(Color.MAGENTA); add(scroller, BorderLayout.CENTER); } //drawing the rectangles// public class DrawingPane extends JPanel{ protected void paintComponent(Graphics g) { super.paintComponent(g); for(int i=0;i<15;i++) { g.setColor(Color.blue); g.drawRect(x, y, 100, 100); g.setColor(Color.red); g.drawString("hai "+i,x+50 ,y+50); g.setColor(Color.YELLOW); x1=x+100; y1=y+50; x2=x1+60; y2=y1; g.drawLine(x1,y1,x2 ,y2); x1=x2; y1=y2; x2=x1; y2=y1+60; g.drawLine(x1, y1, x2, y2); x+=100+10; y+=100+10; } }
Thanks in advance.
Regards,
Gnanaprakasam
Similar Threads
-
Scroll message
By getkiran in forum Java AppletsReplies: 1Last Post: 03-05-2009, 04:29 AM -
scroll a Jpanel in a JFrame
By nidhirastogi in forum SWT / JFaceReplies: 1Last Post: 09-07-2008, 03:42 AM -
code hint scroll bar ?
By tryit in forum EclipseReplies: 3Last Post: 04-28-2008, 07:07 AM -
Scroll thumb on the ScrollPanel
By SteM in forum AWT / SwingReplies: 3Last Post: 12-05-2007, 06:35 PM -
Jtextarea and scroll
By ziniestro in forum AWT / SwingReplies: 2Last Post: 06-01-2007, 03:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks