Options menu for one cell in java table - java

Welcome
In this table, I made the column mentioned cells editable to let the users make the needed value as they want ...
But they told me the values of this column can take just one of the values: 25,50,75,100, so, they asked me I make an options menu (like it is mention in the pic) allow them to choose directly the needed value and working fast.
So, how can I solve it, please!
(note: I'm working with java swing)

It's not the same question, but you can take a look on solution from below question:
How do I create a right click context menu in Java Swing?
you should create such listener, and add it to your Cell / Table.
you can take a look on below question to understand how to add listener to your Cell (it's not obvious :/)
JTable cell listener?

Related

How would a dev make a JTable LOOK editable

I'm writing an application that has a JTable, and an edit button that sets the current selected row to be editable. Then once the user is done altering the data, they can click the edit button again (with text that now says "Save") to save the data.
The problem is though, when I set a row to be editable, there isn't a visible difference. I could add some code to the renderer to draw the editable cells a little differently, but I don't know what the proper way to make a cell look editable is. Change the color? Make it look like a JTextField? What's the standard method?
Thanks!
Really this is a user interface design question, not a programming one.
To do what you want you need to supply an appropriate cell renderer with the changes you desire but you will need to decide on your own settings. One option might just be to look at the difference between an editable and non-editable text area and apply those to all the cells on the table. This may be as simple as setting the renderers to disabled for any read-only rows.

how can i programatically select a particular text from JTable when i do search in it?

here are the screenshots of the application
Rows will be displayed in the Table according to the text which is written in the search textfield.
Now i want to mark that particular text as per the shown in the second image with the yellow color
I know how to select a row or a particular cell.
but I don't know how to select a particular text inside the cell of any row in the table.
I am guessing you know how to search in JTable, so I am not pasting code of it here.
You can look over the SwingX library. It has this kind of function as you said predefined it it. You just need to add it to your table. This is where you can find it. Give it a try you will surely like it.
The basic premise would be to use a custom TableCellRenderer that provided the functionality that you require.
The problem is how to implement it.
I would create a TableCellRenderer based on a JTextField, remove it's border and make it transparent. This will allow you to use the text highlighting functionality provided by JTextCompoent to highlight portions of the text, as demonstrated here.
The next problem is then knowing what to highlight. There are a number of possibilities.
You could provide a method in your table model that could return the current text that should be highlighted.
I'd, personally, probably use the JTable#putClientProperty and JTable#getClientProperty methods to seed the search text.
Or, you could actually provide a simple model that directly to the renderer which had a method that returned the current search text. This might actually be more useful as you could link it to field, the method building the filter and the renderers and allow them to simply seed each other

Set number of options shown in JComboBox when used as JTable RowFilter

I'm trying to set the number of options shown in the JComboBox drop down list when it is used as a JTable RowFilter. Specifically, the filter on occasion can have many options and I'd like to show twice as many as the default (which appears to be 8). See this image:
Combox Box Example http://aalto.tv/test/combobox-image.png
As you can hopefully see, this ComboBox only shows 8 items and I would like to show more if there are more to be seen.
Having searched around the popular solution is to call "setMaximumRowCount" on the JComboBox, however this is having no effect.
Can any one point me in the right direction?
Many thanks for any and all help!
Cheers,
Alex
try the revalidate() (or repaint()) method after setting the rowcount;
if a setXX method does not generate an event to the component, then you have to manually reset it.
failing that, look at the source code of the setMaximumRowCount() method
JComboBox#setMaximumRowCount works for JTable / TableHeader and AutoComplete JComboBox in the JTable too

How to make an expandable list with Java Swing

I need to make an expandable list using java swing. I will attempt to demonstrate:
Unexpanded:
>[Expand me!]
>[And me!]
Expanded:
|[Expand me!]
>[Expand us too!]
>[Expand us too!]
>[Expand us too!]
>[And me!]
So, when you click on the "Expand me" portion of the list, another lists will drop down, possibly containing more expandable lists. If you were to click on it again, it's "sub-lists" would then retract. Pretty basic. And, as you can see, I am not looking for JComboBox, and I do not think JList can do this. If someone were to point me in the right direction, or give some programming examples, I would be grateful.
Thanks,
MirroredFate
How about using a JTree.
A control that displays a set of hierarchical data as an outline.
You can try using a JTable and put a button in the first column. When the button is clicked you add more data in the rows in between.
update
Something like this:
Or this
I think the first uses a JTree but that the idea.
BTW these two belong to JIDE Soft, check if it is feasible for you to buy a license:
http://www.jidesoft.com/products/grids.htm
Is not trivial to roll you own but is not impossible either.
check for TreeTable or one example or Outline, but with notice, that on official Java (SnOracle) pages any progress died ...,

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:
Properties (superclass)
PropertiesToLet(extends Properties)
PropertiesToSell(extends Properties)
EstateAgent (GUI to manage the properties)
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.:
Add and Remove a tenant from a PropertyToLet
base on a tenant you can collect the rent and pay the rent and see how much rent is left to pay.
Add and Remove a purchaser from a PropertyToSell (the sold will then change according if there is a purchaser or not)
So basically there are several ways how to continue from here. For instance it could be a behaviour like this:
RightClick on the property opens a context menu where the mouse is and I can choose other options such as: Remove Tenant, Add Tenant, Collect Rent, Show Rent Owed, Add a purchaser, Remove a purchaser ---- ofcourse depending on what kind of property it is.
Double click on a row => edit the property ( have a look at this screenshot)
it shows a window that I use to add a property - I could add all the values in the field and that button changes to "Update Property"
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.
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 ;-)

Categories

Resources