-1

What is the easiest and best way to display array list in window builder? I'm trying to create simple application to manage database. I have managed to create very simple version with text fields for each part of array list, but i want to go step higher. Rows must be clickable so i can get information about clicked row to edit it.

I have heard JTable is good but some people say it's not supported for array lists, and i suppose they are right because i couldn't display anything for like an hour now.

John
  • 21
  • 3

1 Answers1

0

I have heard JTable is good but some people say it's not supported for array lists

You should then probably stop listening to the people who told you so. A more reliable source tells us:

A table model object must implement the TableModel interface.

( from here ).

Guess what: that TableModel interface, it doesn't say anything about how the underlying data is stored! It only asks how you get to rows and columns. Which is pretty straight forward when you have a single backing list: you have one column, and each element in your list represents one row in the model.

So, yes, a JTable sounds like a good "next step" for you, as it allows you to easily gain control over editing and clicking. And more importantly, you only need one JTable instance. Instead of having one textfield per List member!

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • I still can't make it accept arraylist, i just converted it to array. But now it's not really better, because when i try to display it in JTable it just shows me (probably) reference to array in first cell and that's it. I know why, but i'm not sure how to "bypass" it. – John Jun 04 '19 at 15:14
  • Ok i'm stupid, i have managed to make it work. I would want it to display column names on top, but it's something anyway. – John Jun 04 '19 at 15:20
  • @John These things simply take time. I put up that link to the Oracle tutorial intentionally. Step back, and look at that existing code. Carefully read that page. Maybe not once, but 10 times. See if you get their examples to work, and then play with that. And then, when you still cant get your own code to work, then write up a *new* question, that contains a good [mcve]. – GhostCat Jun 04 '19 at 15:26
  • I have found out it works very well with scroll pane. For now i need only one more thing. Hopefully it's "interactive", so i can click on it. Once i click on specific cell, is there any method to take information inside (save to variable etc)? For example i want to click on a cell, click "delete" button and whole element will be removed. I have everything set up, but i don't know how it works with JTable. – John Jun 04 '19 at 15:41
  • @John It is a long time since I worked with these things. I guess you will need an action listener for that button that knows the table. When the button is clicked, it asks the table if it has a currently selected cell. I guess it should work that way. If not, I can only repeat: when you have a new question, ask a new question. This here is not a free tutor service where people sit down and work with you through all stages of your project. – GhostCat Jun 04 '19 at 15:54
  • Yeah i'm aware of that. The only thing that i cannot do now is how to check is cell clicked, if i won't find anything i guess i will ask new question. – John Jun 04 '19 at 16:05
  • There should be some way to ask for *selected* cells! – GhostCat Jun 04 '19 at 16:12