#Text Field in Table View

1 messages ยท Page 1 of 1 (latest)

oblique python
#

I got one table view to work, but I cant get an additional table view to have a text box in the columns

ripe otterBOT
#

<@&987246487241105418> please have a look, thanks.

ripe otterBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

oblique python
#

am I supposed to have two different controllers for each table view?

muted vortex
#

depends on design

oblique python
#

I mean I got it to work on one table view

muted vortex
#

only saw a section of your other convo buzzing before u closed it, but it's most likely the problem

oblique python
#

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());
            }
        });```
ripe otterBOT
# oblique python ```tableEntry.setCellValueFactory(new PropertyValueFactory<Food,String>("itemNam...

Detected code, here are some useful tools:

Formatted code
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());
  }
}
);
muted vortex
#

as i said, depends on design

oblique python
#

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());
            }
        });```
ripe otterBOT
# oblique python ```tableDrinkItem.setCellValueFactory(new PropertyValueFactory<>("item")); ...

Detected code, here are some useful tools:

Formatted code
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());
  }
}
);
oblique python
#

this is table column #1 of table view #2

#

am I missing something?

muted vortex
#

can u share an actual screenshot of the gui ? ( just incase to rule out potato-potato ( terminology ) problems )

oblique python
#

sure

muted vortex
#

just to make sure, cause if those 2 sections of code u shared are not the same one, u forgot a big elephant already

oblique python
muted vortex
#

right though so

#

on your 1st code u shared, your talking Food

#

on the second , your also talking Food

#

shoudlnt that be Drink ?

oblique python
#

I deleted the sub class

#

drink

#

so its all Food

muted vortex
#

they are both subclasses ....

oblique python
#

so I should add the Drink class?

muted vortex
#

its an inheretence exercise correct ?

oblique python
#

but Food does not extend anything

#

no its a project which requires inheritance

#

not an inheritance exercise

muted vortex
#

it is then

#

if 2 items share some similarities, its better to make a parent class that holds those

oblique python
#

people here were telling me I dont need the subclass because they dont have any unique variables or methods

muted vortex
#

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

oblique python
#

so I should add the subclassse back?

#

its a simple project

muted vortex
#

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

oblique python
#

its a menu not a receipt

muted vortex
#

are u going to check each order for what type it is , have it cast etc

oblique python
#

I need to fix the table edit part

muted vortex
#

can u share the entire controller then ( not the 2 event lambda's only )

oblique python
#

yeah sure

#

I added a Drink class

#

dont mind the dessert part, its still under construction

ripe otterBOT
muted vortex
#

yeah, kinda knew that higher that it was there ๐Ÿ˜‰

#

hence the design talk :p

oblique python
#

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

muted vortex
#

and the goal is to edit the data that's there so it gets added to the selectable ?

oblique python
#

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

muted vortex
#

this might sting even more

oblique python
#

what?

#

please spare me

muted vortex
#

u got 3 tables, all the same. 3 sources. Why all the different code ?

oblique python
#

what? I dont understand

#

One is for food other is for drink and last is for dessert

muted vortex
#

but all 3 do exatcly the same thing no ?

oblique python
#

yeah

muted vortex
#

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

oblique python
#

๐Ÿ™‚

#

IM happy with what I have

muted vortex
#

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

oblique python
#

I have to make a client server also

#

I think the client server stores menus and you can import export them

muted vortex
#

yeah, then i would defo rethink your design atm before it spins out of control

oblique python
#

its a simple project not like a big business project

muted vortex
#

simple or big, there's no real difference . Generilization does magic

oblique python
#

I dont know how to improve it

#

to be honest

muted vortex
#

u seen inheritance correct ?

oblique python
#

yeah

#

thats just one requirement of the assingment

muted vortex
#

consider boat - bus - train - zeppelin as classes

oblique python
muted vortex
#

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

oblique python
#

I know that

muted vortex
#

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

oblique python
#

more like menu categories

#

not items

muted vortex
#

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

oblique python
#

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

muted vortex
#

Usually people do the inverse, but as u found out, u lost a lot of time on something already

oblique python
#

all I had to do is click editable

#

at least I got it working