#Text Field in Table View
1 messages ยท Page 1 of 1 (latest)
<@&987246487241105418> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
am I supposed to have two different controllers for each table view?
depends on design
I mean I got it to work on one table view
only saw a section of your other convo buzzing before u closed it, but it's most likely the problem
having one controller is the problem?
tableEntry.setCellFactory(TextFieldTableCell.forTableColumn());
tableEntry.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<Food, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<Food, String> t) {
Food food = t.getTableView().getItems().get(t.getTablePosition().getRow());
food.setEntry(t.getNewValue());
}
});```
Detected code, here are some useful tools:
tableEntry.setCellValueFactory(new PropertyValueFactory<Food, String>("itemName"));
tableEntry.setCellFactory(TextFieldTableCell.forTableColumn());
tableEntry.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<Food, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<Food, String> t) {
Food food = t.getTableView().getItems().get(t.getTablePosition().getRow());
food.setEntry(t.getNewValue());
}
}
);
as i said, depends on design
this is table column #1 of table view #1
tableDrinkItem.setCellFactory(TextFieldTableCell.forTableColumn());
tableDrinkItem.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<Food, String>>(){
@Override
public void handle(TableColumn.CellEditEvent<Food, String>d) {
Food food = d.getTableView().getItems().get(d.getTablePosition().getRow());
food.setEntry(d.getNewValue());
}
});```
Detected code, here are some useful tools:
tableDrinkItem.setCellValueFactory(new PropertyValueFactory<>("item"));
tableDrinkItem.setCellFactory(TextFieldTableCell.forTableColumn());
tableDrinkItem.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<Food, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<Food, String> d) {
Food food = d.getTableView().getItems().get(d.getTablePosition().getRow());
food.setEntry(d.getNewValue());
}
}
);
can u share an actual screenshot of the gui ? ( just incase to rule out potato-potato ( terminology ) problems )
sure
just to make sure, cause if those 2 sections of code u shared are not the same one, u forgot a big elephant already
right though so
on your 1st code u shared, your talking Food
on the second , your also talking Food
shoudlnt that be Drink ?
they are both subclasses ....
so I should add the Drink class?
its an inheretence exercise correct ?
but Food does not extend anything
no its a project which requires inheritance
not an inheritance exercise
it is then
if 2 items share some similarities, its better to make a parent class that holds those
people here were telling me I dont need the subclass because they dont have any unique variables or methods
yeah for 2 things u normally dont, but think ahead
what if u want to add deserts
wines etc
your going to have to recode your entire thing
it all starts with design
never ever ever ever instantly start coding on 'how' u think it should work
for example, your conclusion that food and drink are the same ( code wise ) is correct
but what if they arent, and u need to make the total
its a menu not a receipt
are u going to check each order for what type it is , have it cast etc
I need to fix the table edit part
can u share the entire controller then ( not the 2 event lambda's only )
yeah sure
I added a Drink class
dont mind the dessert part, its still under construction
I uploaded your attachments as Gist.
if you look here I can edit the table view on the left
but not the drink table on the top right
I been working on this for many days trying to get the edit to work
and the goal is to edit the data that's there so it gets added to the selectable ?
you can edit every cell even the blank ones
I dont understand why the second table doesnt let me edit it
its very frustrating
I figured it out
the table view was not set to editable
!!!!!
i am so dumb
one whole day trying to figure whats wrong
this might sting even more
u got 3 tables, all the same. 3 sources. Why all the different code ?
what? I dont understand
One is for food other is for drink and last is for dessert
but all 3 do exatcly the same thing no ?
yeah
your probably either haven't seen this or your not fluent in it then. If mulitple items do the same thing , but on a different source, find a way to make it accept all the sources
like
u got your 1st table working, the other ones are identical so they should work aswell
If all falls down to how u are suppose to handle it and u start reading and breaking it down. Your making a menu, so it consists out of menuItems. No matter how many catogorys u got, u still make it on the same parent
I have to make a client server also
I think the client server stores menus and you can import export them
yeah, then i would defo rethink your design atm before it spins out of control
its a simple project not like a big business project
simple or big, there's no real difference . Generilization does magic
u seen inheritance correct ?
consider boat - bus - train - zeppelin as classes
all different things, different propulsion, capacity etc
yet they have a huge common things, which makes it easy to make them inherit
all those 4 things are a Vehicle
I know that
so if u code anything for those 4, u make it accept a vehicle, not the item itself and that code will work for any of those 4 , and any that gets added after
its the same with your execercise
your making a menu that has menuitems
it does not have food, drink, dessert etc, it has menu items
however, a food is a menuitem
so is a drink
and a dessert
yeah they are all part of the same menu
menu should be the parent
and food, drinks, dessert are the subclasses
is that what you are saying?
I was lazy and I was trying to get the code to work
mainly I was testing the code before I change the hierarchy
Usually people do the inverse, but as u found out, u lost a lot of time on something already