aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Alignment of JTextArea in OverlayLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Alignment of JTextArea in OverlayLayout" Watch "Alignment of JTextArea in OverlayLayout" New topic
Author

Alignment of JTextArea in OverlayLayout

Mary Anu
Greenhorn

Joined: May 01, 2004
Posts: 10

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.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
You can do what you're describing but it seems like a lot of work. This is a little different approach to adding notes to an image.
Mary Anu
Greenhorn

Joined: May 01, 2004
Posts: 10

yes......... I tried it and its working fine. Thanxxxxxxxxxxx a lot.

But after entering the comments can i save the image as a new image with comments into my local machine?

regards
anu.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Alignment of JTextArea in OverlayLayout