Richard
Richard

Reputation: 1590

Java table arraylist modification

Basically it's a task to manage properties, and I am doing a much more complex solution than it is required. It is just the last bit where I struggle.

To give you an idea of what we have:

So the part I am struggling with is basically the EstateAgent class.

What I wrote so far: http://pastebin.com/0qieM67j

That a about 500 lines - But I need help with the theoretical part not the programming part - because I dont want you to do my coursework - I just need the solution how to approach that.

The lines I am struggling with are from: 55 to 113

Its about a table that I create and insert rows into it. Each row represents a property. It could be a propertyToLet or a propertyToSell object. Those properties come from my ArrayList<Property> properties.

The inserting row and showing the table is fine and it is working the way it should. So there is problem with the code. I apologize for the code structure - but we are limited in the submission - so we cannot submit more than 4 files those file are obviously the named classes - so I cannot extend any more classes or files to the project.

So what I want to do now is: Editing a property.

I have the row that represents a property. It is showing me the position in the arrayList and all the values that I can get.

So now there are a few more possibilities.:

So basically there are several ways how to continue from here. For instance it could be a behaviour like this:

enter image description here

That would be one solution another one would be: - Edit the cell of the row => changes the value of the property (they will inspect the object and see if that really changed and not just the row value)

That are my ideas of how to inject the last steps of bringing the functionality into the application.

So here are my questions:

And than I need an outside opinion what is easier and faster to implement in this very limited task. The way of opening the existing add window and change it to an edit window - I don't want to have redundant code! Or changing the value by editing the cell so that the values in the arraylist change.

I need some help with the approach what is easier and what is better.

I really appreciate any help here!

I am looking forward to see some answers.

EDIT I finished the popup Menu thank you for your help. I edited the question as wel.

Upvotes: 4

Views: 500

Answers (1)

kleopatra
kleopatra

Reputation: 51536

Since jdk5, the recommended way to attach a JPopupMenu to a component is

   component.setComponentPopupMenu(menu)

This popup is automatically shown when a user gesture (mouse or keyboard) is interpreted as popup trigger - which may vary across OSs.

As to selecting a row on right (popup-trigger) mouseEvent: it's not done by default in Swing, but seems to be the norm nowadays for (near-)native applications (on vista) - arguably a but in Swing. Volunteers to report, anybody ;-)

Upvotes: 2

Related Questions