Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

disable selection of some cells in a JTable ... Rate Topic: -----

#1 alpha02  Icon User is offline

  • Sexy DIC God
  • Icon

Reputation: 19
  • View blog
  • Posts: 785
  • Joined: 20-May 06


Dream Kudos: 900

Share |

disable selection of some cells in a JTable

Posted 12 August 2007 - 11:28 AM

Hi all, I made a calendar using a JTable and numbers in cells. But I need to make the cells without numbers (null value) unselectable.

I tried making it in my ListSelectionListener:

public void valueChanged (ListSelectionEvent e){
	int r = lvwCalendar.getSelectedRow();
	int c = lvwCalendar.getSelectedColumn();
	if (r != -1 && c != -1){

			if (lvwCalendar.getValueAt(r, c) != null && e.getValueIsAdjusting() == false){
		 //Selection OK
		}
			else if (e.getValueIsAdjusting() == false){
		  //Prevent selection
		 }
	}
}


I really can't figure out how to do it, any help please? Thanks.
Was This Post Helpful? 0
  • +
  • -


#2 1lacca  Icon User is offline

  • code.rascal
  • Icon

Reputation: 40
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05


Dream Kudos: 0

Re: disable selection of some cells in a JTable

Posted 12 August 2007 - 02:15 PM

Unselectable, or uneditable? The latter can be done easily via the TableModel.isCellEditable(int row, int col) function (so a custom TableModel is needed).
Making cells unselectable might require a bit more work, but I think it can be done something like this.
I don't know for sure, but there might be an easier way, too.
Was This Post Helpful? 0
  • +
  • -

#3 alpha02  Icon User is offline

  • Sexy DIC God
  • Icon

Reputation: 19
  • View blog
  • Posts: 785
  • Joined: 20-May 06


Dream Kudos: 900

Re: disable selection of some cells in a JTable

Posted 12 August 2007 - 08:10 PM

I will consider your link as a solution if I can't find something simpler, but it's great, thanks. But do you have something simpler with less code?
Was This Post Helpful? 0
  • +
  • -

#4 1lacca  Icon User is offline

  • code.rascal
  • Icon

Reputation: 40
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05


Dream Kudos: 0

Re: disable selection of some cells in a JTable

Posted 12 August 2007 - 10:15 PM

If I had, I would have posted it, believe me ;) But wait for a while, maybe someone else knows a simpler way.
Was This Post Helpful? 0
  • +
  • -

#5 alpha02  Icon User is offline

  • Sexy DIC God
  • Icon

Reputation: 19
  • View blog
  • Posts: 785
  • Joined: 20-May 06


Dream Kudos: 900

Re: disable selection of some cells in a JTable

Posted 14 August 2007 - 12:11 PM

Can't I simply override a JTable or DefaultTableModel method which processes cell selecting? It would be much simpler than creating a table, a model, a UI...
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users