I want to create a popup user input getter that will show a table like field with multiple text lines.
As an example, I would want a window with 10 rows of text lines and a label to the left side saying what each entry is, and would want to populate it with some default value.
Kind of like this but just the left table and I can modify the white boxes and press confirm.
Is this possible in Swing?
CodePudding user response:
Refer to How to Use Tables [https://docs.oracle.com/javase/tutorial/uiswing/components/table.html] which is part of Oracle's Java tutorials. – @Abra
With this tutorial, I was able to see most of what you are looking for, but it is asking for the names to go on the top with the Object Array like so:
// [rows][columns]
JTable(Object[][] rowData, Object[] columnNames)
It appears that may be the only way to set names in a JTable (column instead of by row). You mentioned a label to the left side saying what each entry is and that gave me the idea of using the html tag as shown here:
How do I put html in a JLabel in java? -- NOTE this syntax is not exclusive to the JLabel
And because I don't see it on that page, I'll include one more piece of information. In order to have multiple lines, you will need to use <br>
(break) like so:
<html><tagHere>"first row"<br>"second row"<br>"third row"</tagHere></html>
Or you could set the table one column wider than you need, set the contents for rowData[rowIndex][0]
to be the description, and keep that from being edited.