Jtable seclections

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Jtable seclections

KP Kirchdörfer
Hi;

I know this is a java question, but I'd like to ask here first before going to
a java forum, due to friendly and helpful approach.

I've managed to create and fill a Jtable with the help of a DefaultTableModel;
I've also managed to print the whole table (jtable.print() - that was too
easy :))  and I can make and undo selections (SingleIntervalSelections) with
the appropriate MouseListeners.

I googled and read a lot esp. the Java Tutorials, but I don't got a clue how
to deal with the selection.
I'd like to print or copy to clipboard the selected rows and columns, but I'm
stuck, how to get the "content" of the selection for further processing. I'm
under the impression, I'm just a small step away, I just don't get it :)

Any hints?

TIA
kp

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Jtable seclections

Kermit Kiser
It's been a while since I messed with JTables but it looks like you need
to get an array of selected row numbers and use that to access the
actual data in the table model - something like this might work where
myjtable is your JTable:

myselection = int[] myjtable.getSelectedRows

mymodel = DefaultTableModel myjtable.getModel

mydata = Vector mymodel.getDataVector

loop myindex =0 to myselection.length-1
 
    say mydata.elementAt(myselection[myindex])

    end

I don't know if that helps as I can't test it now but I wanted to at
least give you something to try.

-- Kermit


KP Kirchdoerfer wrote:

> Hi;
>
> I know this is a java question, but I'd like to ask here first before going to
> a java forum, due to friendly and helpful approach.
>
> I've managed to create and fill a Jtable with the help of a DefaultTableModel;
> I've also managed to print the whole table (jtable.print() - that was too
> easy :))  and I can make and undo selections (SingleIntervalSelections) with
> the appropriate MouseListeners.
>
> I googled and read a lot esp. the Java Tutorials, but I don't got a clue how
> to deal with the selection.
> I'd like to print or copy to clipboard the selected rows and columns, but I'm
> stuck, how to get the "content" of the selection for further processing. I'm
> under the impression, I'm just a small step away, I just don't get it :)
>
> Any hints?
>
> TIA
> kp
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
>
>
>
>  
_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Jtable seclections

Thomas.Schneider.Wien
Hi Kermit,
   thanks a lot for this explanation. It also will help me in my
implementation of PRINT using JTable's
when cross Tables are involved (PRINT A,B,C BY D VERSUS E)

Kind regards,
Thomas.
=====================================================================
Kermit Kiser schrieb:

> It's been a while since I messed with JTables but it looks like you
> need to get an array of selected row numbers and use that to access
> the actual data in the table model - something like this might work
> where myjtable is your JTable:
>
> myselection = int[] myjtable.getSelectedRows
>
> mymodel = DefaultTableModel myjtable.getModel
>
> mydata = Vector mymodel.getDataVector
>
> loop myindex =0 to myselection.length-1
>
>    say mydata.elementAt(myselection[myindex])
>
>    end
>
> I don't know if that helps as I can't test it now but I wanted to at
> least give you something to try.
>
> -- Kermit
>
>
> KP Kirchdoerfer wrote:
>> Hi;
>>
>> I know this is a java question, but I'd like to ask here first before
>> going to a java forum, due to friendly and helpful approach.
>>
>> I've managed to create and fill a Jtable with the help of a
>> DefaultTableModel; I've also managed to print the whole table
>> (jtable.print() - that was too easy :))  and I can make and undo
>> selections (SingleIntervalSelections) with the appropriate
>> MouseListeners.
>>
>> I googled and read a lot esp. the Java Tutorials, but I don't got a
>> clue how to deal with the selection. I'd like to print or copy to
>> clipboard the selected rows and columns, but I'm stuck, how to get
>> the "content" of the selection for further processing. I'm under the
>> impression, I'm just a small step away, I just don't get it :)
>>
>> Any hints?
>>
>> TIA
>> kp
>>
>> _______________________________________________
>> Ibm-netrexx mailing list
>> [hidden email]
>>
>>
>>
>>  
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
>
>

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Tom. (ths@db-123.com)
Reply | Threaded
Open this post in threaded view
|

Re: Jtable seclections

KP Kirchdörfer
In reply to this post by Kermit Kiser
Am Mittwoch, 28. April 2010 09:01:37 schrieb Kermit Kiser:

> It's been a while since I messed with JTables but it looks like you need
> to get an array of selected row numbers and use that to access the
> actual data in the table model - something like this might work where
> myjtable is your JTable:
>
> myselection = int[] myjtable.getSelectedRows
>
> mymodel = DefaultTableModel myjtable.getModel
>
> mydata = Vector mymodel.getDataVector
>
> loop myindex =0 to myselection.length-1
>
>     say mydata.elementAt(myselection[myindex])
>
>     end
>
> I don't know if that helps as I can't test it now but I wanted to at
> least give you something to try.
>
> -- Kermit

Thx Kermit, you've helped me shurely to get on the right track.
I missed the getDataVector method, and at least I was able to see the
selctions and also to see the problems :)
Selections seems to be a real mess, once a user change the sort order.

I started to work with the getValueAt(row, column) method, which is
independent from the users sort order  - but thats another story.

Thanks again
kp



> KP Kirchdoerfer wrote:
> > Hi;
> >
> > I know this is a java question, but I'd like to ask here first before
> > going to a java forum, due to friendly and helpful approach.
> >
> > I've managed to create and fill a Jtable with the help of a
> > DefaultTableModel; I've also managed to print the whole table
> > (jtable.print() - that was too easy :))  and I can make and undo
> > selections (SingleIntervalSelections) with the appropriate
> > MouseListeners.
> >
> > I googled and read a lot esp. the Java Tutorials, but I don't got a clue
> > how to deal with the selection.
> > I'd like to print or copy to clipboard the selected rows and columns, but
> > I'm stuck, how to get the "content" of the selection for further
> > processing. I'm under the impression, I'm just a small step away, I just
> > don't get it :)
> >
> > Any hints?
> >
> > TIA
> > kp
> >
> > _______________________________________________
> > Ibm-netrexx mailing list
> > [hidden email]
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]


_______________________________________________
Ibm-netrexx mailing list
[hidden email]