Rob Camick wrote:Maybe use two JTables
The first displays the Cabin information.
Then when you select a Cabin you populate a second JTable with the Camper information for the Cabin.
So the bottom JTable will be dynamic. You simply change the model of the table every time a new cabin is selected.
All I want is something that just prints out the entire map in the format I described onto a printable screen.
SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834.
Rob Camick wrote:
All I want is something that just prints out the entire map in the format I described onto a printable screen.
Are you saying you want to print this on paper?
If you have lots of Cabins/Campers it won't fit on one page and will just randomly break in the middle of a page.
I would think you want to print one Cabin/Campers at a time.
In any case if that is what you want, then you just need to create multiple panels. On the panel you might have a bunch of labels at the top of the panel for the Cabin information and then use a JTable for the Campers.
So, you create one panel for each Cabin and add the panel to the frame using a BoxLayout.
Then everything will be displayed in one big panel.
The main point is that thereis not component that does what you want, you need to build it yourself.
Do you mean I'd have to create all the panels myself?
If so, that won't work,
Rob Camick wrote:
Do you mean I'd have to create all the panels myself?
Yes.
If so, that won't work,
Of course it will.
1. You write a loop to iterate through the map to get each Cabin
2. Then you create a panel add the cabin information to the panel and add the JTable with the Campers information to the panel
3. Then you add this panel to the frame
4. Repeat steps 2 and 3.
This is basic programming. Rarely will you ever know the exact number of items to process. So you write a loop to process all items.
So, why is this not going to work with a lot of cabins? Can't I just add a scroll bar to the frame?
how will it know where to position the next JTable it creates?
Rob Camick wrote:
So, why is this not going to work with a lot of cabins? Can't I just add a scroll bar to the frame?
What???
You are the one that said it won't work.
I am the one who said it will work, since I made the suggestion on how to solve the problem.
And yes you would want to use a scrollbar since you don't know how many cabins or campers you will have in advance.
This is how you do dynamic programming. You design the form to allow for large amounts of data which means you will potentially need to scroll to see all the data.
how will it know where to position the next JTable it creates?
I have no idea what you are asking. What do you not understand about the looping concept?
You create a single panel with both Cabin and Campers information. So the table (if that is how you want to present the Camper information) is add directly to the panel after the Cabin information.
Then this panel is added to the "main" panel.
The "main" panel is added to the scroll pane.
The scroll pane is added to the frame.
Again, I can only give you the steps (as I understand the question). You need to take the suggestions and do the coding. It should take about 10-15 minutes to try something like this. Then if you have a problem ask a follow up question.
The problem is that the value of the map is not a camper, but a set of campers,
JTables are printed horizontally, not vertically.
Rob Camick wrote:Why do you keep quoting my entire response?
The problem is that the value of the map is not a camper, but a set of campers,
So, you get the Set and iterate through the Set.
How is this any different than iterating through the HashMap to get each Cabin?
JTables are printed horizontally, not vertically.
I have no idea what that means. Each row of the table (which would represent a Camper) is displayed vertically.
I don't have time to answer any more questions. It time for you to actually try writing some code!
Kenneth Milota wrote:Okay, I haven't actually used JTables before. I was just wondering if what I was trying to do could be done
SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834.
Prasad Saya wrote:
Kenneth Milota wrote:Okay, I haven't actually used JTables before. I was just wondering if what I was trying to do could be done
If possible make an image (a sketch on paper and a photo of it) of what the printout should look like and show here (in case if you haven't found a way to do the printing). I'd like to get a clear idea of what you have on your mind.
SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834.
Another option is print in a similar way, but in a spreadsheet (as in MS Excel); yes, this can be done in Java.
SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834.
SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834.
Prasad Saya wrote:What version of Java are you using?
And, are you sure you are using the same class files to create the JAR file?
Here is a link to a topic on solving issues related to Swing GUI: https://docs.oracle.com/javase/tutorial/uiswing/components/problems.html
SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834.
Prasad Saya wrote:I think the data can be formatted into a JTable like in the image below and then printed. I had already provided the links to Oracle's Java examples website where there is info to print.
Another option is print in a similar way, but in a spreadsheet (as in MS Excel); yes, this can be done in Java.
public static TableModel tm(Map<?,?> map){
DefaultTableModel model= new DefaultTableModel(
new Object[]{"Type", "Numbers"}, 0);
for(Map.Entry<?,?> entry: map.entrySet()){
model.addRow(new Object[]{entry.getKey(), entry.getValue()});
}
return model;
}
SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
|