How to draw over a JTable ?

G

Geiregat Jonas

I want to draw (squares ..) over a JTable,
I thoughed of making my own class, extending it with Jtable call paint
and start painting. Would this work ?
 
A

Andrew Thompson

Geiregat said:
I want to draw (squares ..) over a JTable,

As you mentioned over on c.l.j.gui.

Do not multi-post Geiregat, you
risk losing most of your audience
when they will 'plonk' you.
 
A

Andrew Thompson

Geiregat said:
Andrew Thompson wrote: ... ....
Sorry

If you also mean you will be more selective
with groups in future, it's fine. :)

[ Hope you get your answer. ]
 
E

Erica

Geiregat Jonas said:
I want to draw (squares ..) over a JTable,
I thoughed of making my own class, extending it with Jtable call paint
and start painting. Would this work ?

Maybe you find this helpful. Here is the code to draw a fillOval.

public class ColorCircle extends JComponent {
int drawX,drawY,dx,dy;
Color c;
public ColorCircle(int drawX, int drawY, int dx, int dy, Color c){

this.drawX = drawX;
this.drawY = drawY;
this.dx = dx;
this.dy = dy;
this.c = c;
}
public void setColor(Color c){
this.c = c;
repaint();
}

public void paintComponent(Graphics g){
super.paintComponent(g);
if (c != null){
g.setColor(c);
}
g.fillOval (drawX,drawY,dx,dy);
}
}

Then you can create the ColorCircle object and specify the location. Like this:

JPanel p = new JPanel();
ColorCircle s =new ColorCircle(280,0,18,18, p.getBackground());
s.setSize(20, 20);
p.add(s);

Hope this helps.
Erica
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top