Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2005

Tip: Looking for answers? Try searching our database.

Select grid's cells

Thread view: 
aleicaro@libero.it - 20 Jun 2005 09:57 GMT
Hi,
I have the following problem
I Have to represent the 24 hours in a "grid". with 2 rows. The first
row contain the Hours o'clock, and the second row the half hours.
--------------------
1   | 2  | 3  | 4  |
--------------------
1.30|2.30|3.30|4.30|
--------------------

I need to select single cells in this grid, but the selection is not
consequential.
I tried to use the JTable, but searching on the web, I found that with
JTable is not possible to select non consequentials single cells. For
example I need to select the cell "2" and the cell "4.30".

How can I do it?
Does anybody can suggest me a component that can help me to do this if
the JTable is not the right way?

Thank you
Alessandro Rossi
Andrew Thompson - 20 Jun 2005 10:11 GMT
> I have the following problem ..

The multi-posting problem?  
<http://www.physci.org/codes/javafaq.jsp#xpost>

Please take care of that by not (multi-posting).

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

aleicaro@libero.it - 20 Jun 2005 10:19 GMT
I'm sorry,
I saw only after I posted the first message on java.help, that was
present a specific newsgroup for gui troubles...
In the future i'll pay more attention...

Bye
Alessandro Rossi
Andrew Thompson - 20 Jun 2005 10:29 GMT
> I'm sorry,

It's OK given..

> In the future i'll pay more attention...

Yep!  That's what I want to hear (much more than apologies).

> I saw only after I posted the first message on java.help, that was
> present a specific newsgroup for gui troubles...

You can find a basic description of the main Java groups here..
<http://www.physci.org/codes/javafaq.jsp#groups>

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Thomas Fritsch - 20 Jun 2005 18:03 GMT
> Hi,
> I have the following problem
[quoted text clipped - 18 lines]
> Thank you
> Alessandro Rossi

Hi Alessandro!

You could use a bunch of JCheckBox'es arranged under control of a
GridLayout (with 2 rows).
Looking up the javadoc and working out the details is left to the reader
as an exercise ;-)

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

Thomas A. Russ - 20 Jun 2005 19:41 GMT
aleicaro@libero.it wrote:
> Hi,
> I have the following problem
[quoted text clipped - 11 lines]
> JTable is not possible to select non consequentials single cells. For
> example I need to select the cell "2" and the cell "4.30".

Really?  It looks like JTable's setSelectionMode method allows the
following choices by default:

  SINGLE_SELECTION
  SINGLE_INTERVAL_SELECTION
  MULTIPLE_INTERVAL_SELECTION

It sounds like MULTIPLE_INTERVAL_SELECTION is just what you want.

Signature

Thomas A. Russ,  USC/Information Sciences Institute

Thomas Weidenfeller - 21 Jun 2005 08:05 GMT
> Really?  It looks like JTable's setSelectionMode method allows the
> following choices by default:
[quoted text clipped - 4 lines]
>
> It sounds like MULTIPLE_INTERVAL_SELECTION is just what you want.

You apparently never used it. Some "genius" at Sun decided to model the
selection with a combination of a row selection (ListSelectionModel),
and a column selection (ListSelectionModel in TableColumnModel). If you
work with setCellSelectionEnabled a cell is considered to be selected if
its row is marked as selected in the row selection model, and its column
is marked as selected in the column selection model. In other words, the
intersections of row/column selections are treated as a cell selections.

This works fine if there is only one cell to be selected or one
consecutive interval. The mechanism breaks down immediately if you want
to select more than one cell that are not directly neighbours. Because
you end up not only with the desired cells selected, but also with the
set union of all row/column combinations selected. E.g.

Assume you want to select cell (0,0), and cell (10,10). So row 0 and row
10 get marked as selected in the row selection model. And column 0 and
column 10 get marked as selected in the column selection model. But this
means, that also cell (0,10) and (10.0) are considered to be selected.

MULTIPLE_INTERVAL_SELECTION is pretty much irrelevant, because if you
use more than just on selection interval, you get phantom selections. If
you use a single selection interval it happens that the phantom
selections are also desired selections.

There are good reasons why JTable is in general considered to be the
worst Swing component of all (closely followed by JFileChooser). The
above is one of these reasons.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

aleicaro@libero.it - 21 Jun 2005 08:33 GMT
Thank you,
yes I tried to build a panel with a grid layout with 24x2 cells, but I
would like to use something more "pretty" than checkbox. I would like
grid cells that are selected on mouse over...I would like a serie of
squares...how can I realize it?
Liz - 21 Jun 2005 15:34 GMT
Since it is not easy to select non continuous cells in JTable. Why not
acheive the same behaviour by changing the back ground of the cell.
when the user clicks on a cell, change the back ground of the cell to a
different color , at the same time add the cell location to a variable.
Later on you can query the variable to get the selected cells.

If you use free QuickTable java component (http://quicktable.org) which
is an implementation on top of JTable. It is easy to set the background
of the cell.

 class SelectionCellModel extends CellPropertiesModel
 {

  public Color getBackground(int row, int col)
  {
     if( userClickedRowColumn(row, col))
       return Color.blue;
     else
       return null;
  }

   public Color getForeground(int row, int col)
   {
     return null;
   }

 }

http://quicktable.org/doc/quick/dbtable/CellPropertiesModel.html


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.