Search code examples
javaswingjtextareajcomponent

JTextArea with selectable rows


I'm making an application and I need a JComponent that looks like a JTextArea where I can select individual rows.

I know I could do it by using a JTextArea and managing it myself, but there is probably a better way to accomplish what I'm trying to do. The thing is I have no idea what to search for on Google because I don't know how such a component is called.

Here is a picture that shows what I want: Example of what I want

The section with "ADMIN" highlighted is exactly what I'm looking for. From that, I'm going to fill out some informations in other parts of the program, so I need to be able to know what is selected.


Solution

  • That is a JList, not a JTextArea. It has functionality like selection built-in. It can be shown with elements either horizontally or vertically. Please have a look at the official tutorial to which I've linked.