Selecting line from JTextArea

V

vertigo

Hello
I have JTextArea in which in each line i have an option.
I have to do something when i click any of theese options.

I tried to do it in:
mouseClicked(MouseEvent e)
but it's difficult for me to 'translate' mouse position to
line number (which select appriopriate option).

How can i do it ?
Maybe there are other components which support such functionality ?

Thanx
Michal
 
C

Christian Kaufhold

vertigo said:
I have JTextArea in which in each line i have an option.
I have to do something when i click any of theese options.

I tried to do it in:
mouseClicked(MouseEvent e)
but it's difficult for me to 'translate' mouse position to
line number (which select appriopriate option).

viewToModel
getLineOfOffset


Christian
 
X

xander91

How is this actually done? What is the code for it?

I have...

textArea.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent me) {
textArea.viewToModel(textArea, textArea.getLineOfOffset());
}
}

And of course it doesn't work...what should I change it to?
 
X

xander91

How is this actually done? What is the code for it?

I have...

textArea.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent me) {
textArea.viewToModel(textArea, textArea.getLineOfOffset());
}
}

And of course it doesn't work...what should I change it to?
 

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

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top