dcsimg
Alignment of JTextArea in OverlayLayout
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mary_anu
Posted On:   Saturday, October 30, 2004 04:38 AM

Hi, I have a panel, say WorkPanel for which the OverlayLayout is set. I have placed one image into it. And when I click on any area of the image i want to add a textarea (JTextArea) over the image. (ie for adding comments to the image) Now when i add textarea its getting added to the correct position. But when I start typing on the first textarea, all the textareas are moved to the centre of the image, overlapping each other. I am including the code here public class WorkPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); //Draw image g.drawImage(img, sx, sy, this); repaint(); }    More>>

Hi,

I have a panel, say WorkPanel for which the OverlayLayout is set.
I have placed one image into it. And when I click on any area of the image i want to add a textarea (JTextArea) over the image. (ie for adding comments to the image)

Now when i add textarea its getting added to the correct position. But when I start typing on the first textarea, all the textareas are moved to the centre of the image, overlapping each other. I am including the code here




			

public class WorkPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);

//Draw image
g.drawImage(img, sx, sy, this);
repaint();
}

...
...
OverlayLayout overlay = new OverlayLayout(this);
this.setLayout(overlay);

this.addMouseListener(new ImageMotionListener(this));
this.addMouseMotionListener(new ImageMotionListener(this);
...
...
}

On mouse click event

public void mouseClicked(MouseEvent me)
{

int x = me.getX();
int y = me.getY();


JTextArea cb = new JTextArea("comm :");

Dimension dim = new Dimension(60, 50);
cb.setSize(dim);
cb.setMinimumSize(dim);
cb.setMaximumSize(dim);
cb.setPreferredSize(dim);
cb.setLocation(x,y);

workPanel.add(cb);
}







Also when i type on the textarea its not getting expanded as and when i enter contents into it. For this I removed "cb.setMaximumSize(dim)". Then immedietly when i start typing the textarea got expanded to the fullsize of the workpanel.
Also when i removed "cb.setSize(dim)" textarea was not visible.

what could be the problem?

regards
anu.    <<Less

Re: Alignment of JTextArea in OverlayLayout

Posted By:   Anonymous  
Posted On:   Saturday, October 30, 2004 08:57 AM


i was still thinking to your problem.
you could also solve it by creating a vector of TextArea
(one textarea for each comment you add),
otherwise all the textAreas u create end up having the same
event-reaction, beacause the class u have created is not able to recognize the DIFFERENT
components you use to add the DIFFERENT textAreas.
i hope i helped u :-)
P.S take a look inside thread staff, those problem will be managed better.

Re: Alignment of JTextArea in OverlayLayout

Posted By:   Anonymous  
Posted On:   Saturday, October 30, 2004 08:08 AM

I am not swing expert
but i think there are 2 ways to
reach a more workable solution.


-what about using the more flexible JTextPane,
instead of JTextArea?

-anyway there should be some error in the event handler of
your implementation,
beacause the bug occur when you set the TextArea on the panel and write on it.
About | Sitemap | Contact