File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to make first row of JList unselectable like JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make first row of JList unselectable like JTable" Watch "How to make first row of JList unselectable like JTable" New topic
Author

How to make first row of JList unselectable like JTable

Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Hi I am using a JList to show a number of data in tabular format. I can't use JTable(that's my first constraint).

Here is the code I have used. Everything is working fine except the first row is selectable yet. Can anyone share an idea how to make first row un-selectable(e.g. like a header in JTable).



Thanks>


The Best way to predict your future is to create it - Every great individual common man
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Ankur Sharma wrote:I can't use JTable(that's my first constraint).

Why not?

Can anyone share an idea how to make first row un-selectable(e.g. like a header in JTable).

With JTable, the header is actually a separate component, of type JTableHeader.

If you add your JTable to a simple JPanel, you'll notice that the table header is absent - you have to add it manually. JTable has special support for JScrollPane for adding the header automatically, but JScrollPane is the only one.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Ankur Sharma wrote:Hi I am using a JList to show a number of data in tabular format.

... Can anyone share an idea how to make first row un-selectable(e.g. like a header in JTable).



It seems like a strange thing to want to do, but try this:You should probably check the ListSelectionModel API to make sure I haven't missed a method.

The other thing you could do is for the first line of your getListCellRendererComponent() method do if (index == 0) isSelected = false;
That wouldn't change if the top element could be selected or not, but it would be drawn as unselected even when selected, which is almost as good. It's not as clean, but it may suit your needs.

bitguru blog
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

I would suggest adding a JLabel as the scroll pane's header view component.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make first row of JList unselectable like JTable
 
Similar Threads
programatically editing jTable cell based on another cell value
compilation error ,ListCellRenderer implementaion for Jtable
ideas wanted on making this custom JTable cell renderer more efficient
JTable
Row Selection problems with JTable