Jame
Jame

Reputation: 22200

How to draw shapes inside JPanel?

Referring to my earlier question:

Based on your valuable answers, I choose Java 2D library to cater my requirements.

I completely read the above said library and have full understanding of dealing with the graphics stuff, like what to draw and how to draw etc.Now i only left with one question that how do i draw my required shapes inside JPanel and after drawing all those shapes how do i place that JPanel inside a JScrollPane?

Upvotes: 2

Views: 1077

Answers (2)

StanislavL
StanislavL

Reputation: 57421

Override paintComponent(Graphics g) method. Cast Graphics to Graphics2D and use drawShape() method passing all your Shapes

Upvotes: 3

user949300
user949300

Reputation: 15729

You will typically draw your stuff inside a subclass of JComponent, say, MyComponent.

  1. Create an instance of MyComponent, MyComponent myc = new MyComponent();
  2. Put that inside a JScrollPane, e.g. JScrollPane jsp = new JScrollPane(myComponent);
  3. Then add the JScrollpane to the JPanel (exact code depends on the layout manager)

Upvotes: 3

Related Questions