I have a GUI with a row of buttons across the top. Clicking one of those buttons will display a column of buttons down the left hand side. Clicking one of the column buttons will display a row of buttons across the bottom of the screen. Clicking on each button will also show a grid of data in a JTable displayed in the middle of the screen. The purpose is each new set of buttons will allow the user to drill down to finer detail about the data being displayed. The data comes from a SQL Server database. What I want to do, is to hold all of the buttons in some sort of container so I never have to go to the database to get new buttons. The first buttons along the top, Level1, each have their own specific set of buttons that will show up on the left hand side in a column, Level 2. So button 1 will show different buttons in the column then button 2. Each button in the Level 2 column also has a specific set of buttons to show along the bottom, Level 3, so that the top button will show different buttons along the bottom then the next button down. I had thought of a 3 dimensional HashMap, if there is such a thing. The top map would have a button ID as the key, and the value would be another HashMap containing a button ID as the key and another HashMap as the value. The final map would have a button ID and the name to be displayed as the value. I'm not sure this is the best approach. I want to tie them all together, so that each Level 1 button and it's respective Level 2's with their Level 3's are easily accessible. A tree comes to mind but I can't figure out the best solution. Has anyone ever done anything like this?
Currently, I go to the database to get the Level 1 buttons. When one is clicked, I go to the database to get the Level 2 buttons that are specific to the Level 1 button that was clicked. When a Level 2 button is clicked, I go to the database to get all of the Level 3 buttons that are specific to the Level 2 button clicked. I would like to avoid all this back and forth to the database.
So each button at level 1 has a list of buttons which are at level 2? And each button at level 2 has a list of buttons which are at level 3? Then I know what collection I would use to store the relationships.
posted 7 years ago
Thanks for assigning this topic to the proper forum. The button names are contained in the database, that is true. What I need is a container, a HashMap, a 3 dimensional Array, or something to hold the buttons. They have a 1 to many to many relationship with other buttons on the screen. Maybe an example would be better.
Along the top of the GUI are buttons "CAT" "DOG" "Dinosaur"
Pressing the cat button would display down the left side:
You wouldn't want those buttons to show up if you pressed the dog button or the dinosaur button since they are specific to cats.
Pressing a Tiger button would display a list of new buttons along the bottom
"Bengal" "Stripes" and so on.
What I need is a way to keep all of the Cats together.
I hope this makes things a bit clearer.
So each button contains a list of lower-level buttons. The container to use would therefore be a List.
posted 7 years ago
I had kinda gotten you hint in your first post, I'm not sure how to implement it though. Creating a list isn't the problem. What I'm having trouble with is how to get to the lower lever buttons from the top list. I have to name the buttons based on a value in the database, to keep things generic. If the top list has a bunch of names in it, how do I store or retrieve the list of buttons for the lower level?
I had thought of creating a class like a bean and storing some attributes in it.(buttonName, buttonText, buttonColor, etc) Then I could add that object to the list. One of the attributes in the class could be a list so it would have the lower level buttons available by iterating over the list contained in the class.
I'm still not sure this is the best solution though. I will be trying it, and will let you know how I make out.
I dunno. Java is an object-oriented language, so the fundamental thing to do is to design classes which do the things which you want your application to do. And yet people are stuck writing monolithic chunks of code which use only classes from the standard API. There seems to be some big barrier between ordinary programming and object-oriented design, and I don't know why that is the case.
please buy this thing and then I get a fat cut of the action:
Create Edit Print & Convert PDF Using Free API with Java