use JTable in Java netBeans

215 views
Skip to first unread message

Bayan

unread,
Jun 30, 2010, 5:56:16 AM6/30/10
to The Java Posse
Hi,
i try use JTable in netbeans 6.7, i add columns but when i want add
rows, i don't understand how use DefaultTableModel and the order of
instruction.
Can help me for understand that,

Thanks

Wildam Martin

unread,
Jun 30, 2010, 8:03:40 AM6/30/10
to java...@googlegroups.com
On Wed, Jun 30, 2010 at 11:56, Bayan <bay...@gmail.com> wrote:
> i try use JTable in netbeans 6.7, i add columns but when i want add
> rows, i don't understand how  use  DefaultTableModel and the order of
> instruction.

The easiest way is to right-click on a newly created JTable in the
Matisse (=Netbeans Swing GUI editor) -> "Table contents..." -> Columns
-> <add and remove columns as you like> and then switch to code view
and expand the folded generated code.

HTH.
--
Martin Wildam

Bayan

unread,
Jul 1, 2010, 3:28:41 AM7/1/10
to The Java Posse

>
> The easiest way is to right-click on a newly created JTable in the
> Matisse (=Netbeans Swing GUI editor) -> "Table contents..." -> Columns
> -> <add and remove columns as you like> and then switch to code view
> and expand the folded generated code.
>
> HTH.
> --
> Martin Wildam

Thanks for help, but i want add and remove rows, i use Vector of
Element but i don't know how i insert it to Table

Wildam Martin

unread,
Jul 1, 2010, 4:15:32 AM7/1/10
to java...@googlegroups.com
On Thu, Jul 1, 2010 at 09:28, Bayan <bay...@gmail.com> wrote:
>> The easiest way is to right-click on a newly created JTable in the
>> Matisse (=Netbeans Swing GUI editor) -> "Table contents..." -> Columns
>> -> <add and remove columns as you like> and then switch to code view
>> and expand the folded generated code.
> Thanks for help, but i want add and remove rows, i use Vector of
> Element but i don't know how i insert it to Table

I start getting into doubt if I got it right, what you are trying to achieve.

Adding a row to a table with default table model is quite simple -
just to give an example:

public static void addTableRow(DefaultTableModel model, String... columns)
{
model.addRow(columns);
}

Not sure why you are using the Vector.

For setting a particular value by giving it's row and column use
model.setValueAt.
Just an important thing (if you don't already know): Don't mix up row
index in table with row and column index in model - it is not the same
for both if the table gets sorted or columns get moved.
--
Martin Wildam

Kevin Wright

unread,
Jul 1, 2010, 4:19:51 AM7/1/10
to java...@googlegroups.com
Seriously, just go and create your own table model:


It's rare to see anyone use a default model beyond the first 15 mins of prototyping...




--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.




--
Kevin Wright

mail/google talk: kev.lee...@gmail.com
wave: kev.lee...@googlewave.com
skype: kev.lee.wright
twitter: @thecoda

Wildam Martin

unread,
Jul 1, 2010, 4:29:00 AM7/1/10
to java...@googlegroups.com
On Thu, Jul 1, 2010 at 10:19, Kevin Wright <kev.lee...@gmail.com> wrote:
> Seriously, just go and create your own table model:
>  http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/table/AbstractTableModel.html
> It's rare to see anyone use a default model beyond the first 15 mins of
> prototyping...

Indeed - undergone same "conversion", although it took me maybe 30 mins. ;-)

--
Martin Wildam

Reply all
Reply to author
Forward
0 new messages