• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI Newbie Problems

 
David Dickinson
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create a GUI from scratch using Eclipse, the source code must be written by hand and thus no GUI design tool can be used.

My concept at the moment is quite simple but as this is my first GUI in Java I don't know if its possible to do what I want.

I need a series of rows much like a spreadsheet which has information as follows:

Cars
CarA - �5,000 ---------------------- OPTIONS HERE ------------
CarB - �2,500 ---------------------- OPTIONS HERE ------------

Vans
VanA - �15,000 --------------------- OPTIONS HERE ------------
VanB - �12,500 --------------------- OPTIONS HERE ------------


The majority of the screen is split into two "categories" cars and vans, I need to list all cars and vans currently owned by the garage. Now the problem... the number of cars/vans is unknown at design time as the data is read from a file and thus the controls to display this information must be create "on-the-fly" at run time. Is this possible?

Where it says OPTIONS HERE that means I want a series of buttons which offer the user functions related to the row the buttons are placed, e.g. the set of options at the moment looks like the following:

- Sell Car/Van
- Modify Value

If someone hits the Modify Value button on row CarA I want a dialog to appear which has a text field to allow the user to adjust the value then update the "grid".

Can someone point me in the right direction with this? I thought about creating a loop which creates the neccessary rows but I don't know how I would be able identify the specific controls created?

Thank-you
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David,

As fas as I understand your design, it looks like a classical JTable display with few buttons to manage the selected row (To my mind the buttons should be placed close but outside the "data area" and should not be duplicated on each row)

You may look first at the JTable tutorialthen come back here if necessary.

Hope that helps,
 
David Dickinson
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just been reading about JTables and was coming back and ask a related question, Lionel your right they do sound ideal.

I have been looking through the various constructors which exist for JTables and need just a little guidance.

My data is currently stored in ArrayList's and I wish to keep it that way (but could change if neccessary), are ArrayList's interchangable with Vectors? Or would it be better to define my own table model which directly sets each individual column/row from my collections?

Thanks
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David,

Unfortunately you can't use an ArrayList where a Vector is required. however, in this case, you might simply use the ArrayList.toArray() as a parameter for JTable constructors.

Hope that helps,
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lionel Badiou:
Hello David,

Unfortunately you can't use an ArrayList where a Vector is required. however, in this case, you might simply use the ArrayList.toArray() as a parameter for JTable constructors.

Hope that helps,


That's not entirely true. You can write your own TableModel (which you'd want to do either way) and have it use ArrayLists instead of Vectors.
 
David Dickinson
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me why my column names aren't appearing?



The "data section" of the table appears with the correct values but the headings aren't shown.

Thank-you
[ April 21, 2005: Message edited by: David Dickinson ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!