Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Integreating the JScrollPane to JTable

Reply
Thread Tools

Integreating the JScrollPane to JTable

 
 
Happy Day
Guest
Posts: n/a
 
      08-15-2005
Hi Guys,
I've tried to integrate the JScrollPane to the one the the cell in the
JTable.

These are my code I've tried.

================================================== ================
TableColumnModel tcm = table.getColumnModel();
TableColumn destinationColumn;
..
..
..
..


JScrollPane listScrollPane;
listModel = new DefaultListModel();
listModel.addElement("any");
listModel.addElement("1st");
listModel.addElement("dummy1");
listModel.addElement("dummy2");
listModel.addElement("dummy3");
listModel.addElement("dummy4");

list = new JList(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SE LECTION);
list.setSelectedIndex(0);
list.addListSelectionListener(this);
list.setVisibleRowCount(5);
listScrollPane = new JScrollPane(list);
destinationColumn.setCellEditor(new DefaultCellEditor(listScrollPane));
// ?????????????????????

================================================== ================

As shown, I created JList and put it in the JScrollPane. Then, I like
to put the JScrollPane into the cell in the JTable.
I know the last line has the syntax error because the
"DefaultCellEditor" cannot have the scrollPane type.
How can I solve the problem??

Thank you in advance.

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      08-16-2005
On 15 Aug 2005 16:52:24 -0700, "Happy Day" <>
wrote or quoted :

>As shown, I created JList and put it in the JScrollPane. Then, I like
>to put the JScrollPane into the cell in the JTable.
>I know the last line has the syntax error because the
>"DefaultCellEditor" cannot have the scrollPane type.
>How can I solve the problem??


My first reaction is surely you are confused. You put JTables in
ScrollPanes not ScrollPanes in table cells. That is what tables are
for, to efficiently scroll through the cells.

If you actually want a tiny cell that scrolls all within itself, while
the whole rest of the table scrolls, you will need to write a custom
cell renderer and custom cell editor for it.

For that, reading a Swing text book will probably help. You need a
basic component that you keep modifying given data.

You might start with a non-scrolling component, and once you get that
working, add the scrolling. Start with a renderer, then tackle the
more difficult editor.
 
Reply With Quote
 
 
 
 
Babu Kalakrishnan
Guest
Posts: n/a
 
      08-16-2005
Roedy Green wrote:
> On 15 Aug 2005 16:52:24 -0700, "Happy Day" <>
> wrote or quoted :
>
>
>>As shown, I created JList and put it in the JScrollPane. Then, I like
>>to put the JScrollPane into the cell in the JTable.
>>I know the last line has the syntax error because the
>>"DefaultCellEditor" cannot have the scrollPane type.
>>How can I solve the problem??


[snip]

>
> You might start with a non-scrolling component, and once you get that
> working, add the scrolling. Start with a renderer, then tackle the
> more difficult editor.


Unfortunately a renderer cannot scroll (since it will not receive any
events) - so i'd guess it will have to be an editor only.

BK
 
Reply With Quote
 
Rogan Dawes
Guest
Posts: n/a
 
      08-16-2005
Babu Kalakrishnan wrote:
> Roedy Green wrote:
>
>> On 15 Aug 2005 16:52:24 -0700, "Happy Day" <>
>> wrote or quoted :
>>
>>
>>> As shown, I created JList and put it in the JScrollPane. Then, I like
>>> to put the JScrollPane into the cell in the JTable.
>>> I know the last line has the syntax error because the
>>> "DefaultCellEditor" cannot have the scrollPane type.
>>> How can I solve the problem??

>
>
> [snip]
>
>>
>> You might start with a non-scrolling component, and once you get that
>> working, add the scrolling. Start with a renderer, then tackle the
>> more difficult editor.

>
>
> Unfortunately a renderer cannot scroll (since it will not receive any
> events) - so i'd guess it will have to be an editor only.
>
> BK


You could follow the approach used by JTreeTable, and make the cell
always return true for isEditing() (or something along those lines)

i.e. how JTreeTable gets the JTree to open and close . . .

Rogan
 
Reply With Quote
 
Babu Kalakrishnan
Guest
Posts: n/a
 
      08-16-2005
Rogan Dawes wrote:
> Babu Kalakrishnan wrote:


>>
>> Unfortunately a renderer cannot scroll (since it will not receive any
>> events) - so i'd guess it will have to be an editor only.
>>
>> BK

>
>
> You could follow the approach used by JTreeTable, and make the cell
> always return true for isEditing() (or something along those lines)
>
> i.e. how JTreeTable gets the JTree to open and close . . .
>


Are you referring to the JTreeTable class that appeared in the "The
Swing Connection" articles ?

With all due respects to the stalwarts who created the example class/es
(Quite a bit of what I've learnt about the Swing library have been from
following their articles), I've always felt that its design was
something of a hack. Everything in its design "improvements" being some
kind of a workaround to what a JTable is inherently incapable of doing.

Haven't followed the progress of this in the past year or so since I was
too busy in other areas of the technology. But unless something has
drastically changed (which I doubt), renderers are still what they were:
transient beings that paint a cell and then disappear - what you see on
screen is only an image of what they painted a while back - the user
cannot interact with them - period.

BK
 
Reply With Quote
 
Rogan Dawes
Guest
Posts: n/a
 
      08-17-2005
Babu Kalakrishnan wrote:
> Rogan Dawes wrote:
>
>> Babu Kalakrishnan wrote:

>
>
>>>
>>> Unfortunately a renderer cannot scroll (since it will not receive any
>>> events) - so i'd guess it will have to be an editor only.
>>>
>>> BK

>>
>>
>>
>> You could follow the approach used by JTreeTable, and make the cell
>> always return true for isEditing() (or something along those lines)
>>
>> i.e. how JTreeTable gets the JTree to open and close . . .
>>

>
> Are you referring to the JTreeTable class that appeared in the "The
> Swing Connection" articles ?
>
> With all due respects to the stalwarts who created the example class/es
> (Quite a bit of what I've learnt about the Swing library have been from
> following their articles), I've always felt that its design was
> something of a hack. Everything in its design "improvements" being some
> kind of a workaround to what a JTable is inherently incapable of doing.
>
> Haven't followed the progress of this in the past year or so since I was
> too busy in other areas of the technology. But unless something has
> drastically changed (which I doubt), renderers are still what they were:
> transient beings that paint a cell and then disappear - what you see on
> screen is only an image of what they painted a while back - the user
> cannot interact with them - period.
>
> BK


Sure, it seems like a hack to me, too. I don't think that there have
been any adjustments to the source in the last couple of years, at least.

Effectively, what I see as the key "trick" here is this snippet from
AbstractTreeTableModel.java (possibly resulting from some hackery of my
own, but still):

/** By default, make the column with the Tree in it the only
editable one.
* Making this column editable causes the JTable to forward mouse
* and keyboard events in the Tree column to the underlying JTree.
*/
public boolean isCellEditable(Object node, int column) {
return getColumnClass(column) == TreeTableModel.class;
}

Which effectively makes the TreeTable use an editor all the time, I
think, rather than a renderer.

Rogan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jscrollpane and jtable yashiro Java 2 05-17-2008 11:52 AM
JTable and JScrollPane helmut.teichmann@opb.de Java 3 07-19-2007 12:35 PM
Set size of JTable inside a JScrollPane Allan Valeriano Java 1 06-16-2007 05:22 AM
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57