Question

I'm working on a extremely basic Java video player project which is my coursework. I've 2 JTextPanes: 1 for listing all videos and 1 for creating playlist.

So far the only way I could add videos to the playlist is to put video id(from database) in a text field and click add button. But I would like my player to have the functionality to add videos to the JTextPane, or anything else if you think is better(for playlist), by clicking on the column of the JTextPane(all videos). I guess I have to add mouse listener to the JTextPane.

But how do I add mouse listener to each of the column of the JTextPane? Any help & suggestions greatly appreciated!

Thanks in advance!

Was it helpful?

Solution

You probably want to change to using a JList, since you are handling a list of all videos.

You can then easily find which video the user has selected, usig JList.getSelectedItem() and add it to the playlist.

You cannot add a MouseListener to specific rows (did you mean rows, not columns?) of a JTextPane, only to the pane as a whole. You can, however, find out where in the text the user has clicked, using JTextPane.viewToModel(Point p). This is probably a needlessly complex way of doing lists, however.

OTHER TIPS

You can use this to get row/col position in JTextPane http://java-sl.com/tip_row_column.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top