Results 1 to 8 of 8
- 07-30-2012, 08:45 PM #1
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Swing - What components to use? Logging software.
Hello!
I'm still a newbie at coding, but I feel like I can create the simple programs that I myself feel like I am missing or finding a need of. Right now, I've been working on a program to keep track of my wine cellar and the wines in it. I've coded a program that works fine for my needs, though it's missing a GUI. My plan is to share the program with a few of my friends, and because of that I thought it might be good to learn some GUI programming.
The program itself is very simple. One creates a new wine object, which then is stored in an ArrayList for those objects. The list is saved in a file and read when the program is reopened, so the entries are kept in between sessions. What I would like to accomplish with the GUI is a window that displays the list of wines and some of the attributes the wine objects has.
Something like the following Photoshop-sketchup:

- Buttons
The buttons will be JButtons, very simple and I know how to use these in the proper way. - Text
The text below the buttons will be JLabels that display various information.
My big question is how to display the attributes of the wines that are stored in the ArrayList. The list may contain hundreds of different wines, and I want to have something looking as the above sketch that is also scrollable.
Objects of the wine class has the following attributes:
Not all of these have to be displayed in the GUI, though I would like to have most of them in a column each. I'm also thinking about the possibility to sort the list in different orders, e.g. price/vintage decscending/ascending order.Java Code:String country; String name; String extName; int vintage; double price; String character; String grape; int amount; int storage;
I've done some reading into what type of Swing component could be the best to display the information I want to display, and I figure I could perhaps use a JTable. Looking at Oracles tutorial site, I found this suitable picture:

This might be a bit silly, but I'm just looking for a type of confirmation that I'm looking in the correct way. Is it possible to use a JTable component to achieve what I want to achieve, or should I perhaps use something else that I haven't thought of?
Any thoughts of insights and tips are welcome!
Thank you,
Z!
- 08-02-2012, 03:49 AM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Re: Swing - What components to use? Logging software.
Looks fine to me. But I would be wary of using text files as databases. You could end up with read write access issues.
-
Re: Swing - What components to use? Logging software.
A JTable looks to be perfect for something like this.
- 08-02-2012, 04:25 AM #4
Member
- Join Date
- Mar 2012
- Posts
- 26
- Rep Power
- 0
- 08-02-2012, 10:58 AM #5
Re: Swing - What components to use? Logging software.
For something as simple as this, you could make your wine bottle class Serializable and serialize the whole ArrayList to a file.
Get in the habit of using standard Java naming conventions!
- 08-02-2012, 11:36 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Swing - What components to use? Logging software.
Please do not ask for code as refusal often offends.
- 08-04-2012, 09:56 AM #7
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Re: Swing - What components to use? Logging software.
This is basically what I want it to do, therefor I thought there wouldn't be any problems just to write a file, read file, write back to file.
---
Thanks for all the great answers, I'm currently looking into using JTables, and I'm slowly learning to use it in the way I want to!
kjkrum - I will look into your suggestion aswell! I haven't heard about Serializable before, so it is def. something I should read about!
Thanks all,
Z!
- 08-05-2012, 01:16 PM #8
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Re: Swing - What components to use? Logging software.
I've run into a few questions regarding the display of different data types in the JTable.
As an experiment to understand how the default table model works, and how I can populate a table with information, I've used a for-loop that put String-objects into my JTable. I found some good JTable guides and got it working.
I have the following code to create a JTable:
The columns are to be populated with data from the SBWine-objects that are stored in an ArrayList<SBWine>.Java Code:JTable table = new JTable(); DefaultTableModel model = new DefaultTableModel(); table.setModel(model); model.setColumnIdentifiers(new String[] {"Name", "Country", "Vintage", "Price"});
To do this I can use a for-loop, but so far I've only managed to get it working on String objects.
I do not know how to display the values of Vintage and Price. They are of the datatypes Integer and Double. Do I manually have to run a toString(); before adding it to my JTable, or can I set the model to accept a certain datatype in one of the columns?Java Code:for (SBWine p : wineList) { model.addRow(new String[] {p.name, p.country}); }
If possible, I would want to keep the data types that they are in, since I cannot really find a good reason to display a number as a String, and I might want to be able to sort the data later on, and therefor simplify the future coding.
Thanks for all the help and support so far,
Z!
Similar Threads
-
Swing components are not well-displayed
By Josep_16 in forum AWT / SwingReplies: 1Last Post: 08-21-2011, 02:37 AM -
binding swing components
By furqankhan in forum Advanced JavaReplies: 1Last Post: 06-25-2010, 12:08 PM -
Problem In Swing Components
By SANDY_INDIA in forum AWT / SwingReplies: 1Last Post: 07-19-2008, 10:23 PM -
Tab order on swing components
By ashvin@projectdemo.biz in forum AWT / SwingReplies: 1Last Post: 05-31-2008, 10:06 AM -
Where is it best to declare swing components?
By MacNstuff in forum AWT / SwingReplies: 1Last Post: 02-06-2008, 12:59 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks