Best way to display array list in window builder [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
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.

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!

Related

Should I store data in db or should I store it in enum? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Data is very small like list of fruits and won't be changed often, also only one service will be using this data and serving to other services, please mention advantage and disadvantage of your approach.
I think it is better store it in a database's table.
If you store it in a enum, when you add, change or delete a fruit you have to compile your code again. In case of change, you will have to update all places (tables columns) where this fruit's name is store.
In the database you could opt to save it as a single column table or a two columns table (id, fruit_name).
I will opt the second option. Because if you choose the single column option, and you change a fruit name you will have to change it in all the tables where the fruit name is store (like in enum). A disadvantage with the two columns table is that you will have to make joins with the fruit table to get the fruit name (but make this joins is easy and simple).
I think it depends on how often there should be a change and who needs to change it. If you want the employer to be able to change them easily, you may wanna save them in the db and provide them with an api or some kind of ui so they can change whenever they want easily.
but if you yourself need to update it once each year, I see no necessity that you do not hardcode the thing.

Should i store one arrayList per file or should i store all my arrayList in the same file? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm doing my first Mobile App and i have been studying java for about 2 weeks now so i'm pretty new.
The app that i'm trying to make is a grocery list app.
Basically, I want to sort my grocery list by department wise. For example:
Fruit items will go in a fruitArray
the meat items will go in meatArray
etc.
Should I create a single file for each department (Fruit, meat, bakery) or can i store all my array in the same file and access them separately?
I did some search but i cannot find a topic that answers my question.
I would like to know what would be the best way to do it and if it's to put the arrays in the same file, how can i do that ?
Thanksâ˜ș
When you're doing or learning something new, do whatever works for you. Consider trying to do both, as it's experience you'll gain for future.
Some general things to take note of though :
Storing all items in one file could potentially create one massive file (regardless of the project you're working on, im generalizing now)
Storing items in different files increases the overhead of having to handle and manage different files.
These are things you will have to consider and things you'll learn from experience, based on the project and various different aspects.
For the sake of this question, I think storing different items in different files would potentially be a better, simpler solution for now, but it really depends on the entire project and how you plan to implement it. Hope this at least somewhat answers your question. Happy coding and happy learning

Java model best practices SQL - JSON -VIEW [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
While working on a Java web application I was wondering if my model layer was written as it should be. For instance, let's say we have a table USER in our SQL database which consists of 15 columns. Now, when we SELECT all of the columns with SQL we map it to a Java class, serialize via JSON and send it via network to some View and show it on screen.
In a second scenario, we want to select only 2 columns on screen so we do SELECT c1,c2 FROM USER. Thats where my question comes in... am I supposed to map those columns to a same Java model class? Or should i create a new mapper and class to fit it? Both of the approaches seem to have drawbacks, separate class for each query is more work, but it makes sure you always know what data it contains, rather than checking for nulls or working with optionals, also it prevents you from mapping columns you actually don't need.
What is your opinion? Thanks a lot!
Technically you could reuse the same User class for full 15-attribute as well as partial 2-attribute entity. But that will come with a price. Every time you'll see an instance of User class in the code your will have to think if it's the full entity or the partial? Which fields may or may not be null? This will make it much harder to reason about code.

how to build a table of items and it's radioButtons with a dynamic size? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to build a table, with some items, and for each item I want to have its own radioButton. but the input is dynamic. so the size of the table is dynamic, and the "ActionCommand" for each radioButton is dynamic.
what is the best way to do this?
the only way I know is to normally just make a dynamic list of radioButtons and initialize it dynamicly with the names of the items.
thank you
Depends of what you want to do after ? You have to give more details...
If it's for printing, you can take a look about JTable (or more powerful JXTable) which can handle your data with a specific model (model which you have to define).
Just remember to set the action command to each radio button before adding to the table. You'll have to take the time to read doc about this, but with some tests it givesa very good result !
Else, yeah, just a map, with the name of the item, and the radio button.

Search a object without iterating a collection in java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How to look for a particular object in a large list(java collection) without iterating it. Assume we have a large collection and just need to check whether a object exists or not without iterating.
Ok, Let's step out of the binary world.
Think of a chest full of Lego parts. You want a 2x2 flat black piece.
How would you find it without looking in the chest?
There is no magical to find it, you need to jump into the chest and find the piece grabbing one by one and checking if it's the one you are looking for.
There are ways to speed up the process.
You can Organise (sort your collection) by colour for example and just look in the black pile.
Or you can map (Index your pieces) so you know the position of the piece and can go and retrieve from you know where the piece is.
That is, in a very simplistic way, the same idea for databases and collection.
So, summarizing, no, you can't not just find without looking. Sorry :(

Categories

Resources