-3

I have a JTable containg a wordsearch puzzle and a drop down menu below it containing a list of the words contained in the puzzle. I am hoping to find a way to have it so that when a word is selected in the drop down menu it highlight or font changes in the JTable. Any ideas would be helpful.

  • 1
    [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – user1329572 Nov 27 '12 at 15:11
  • Well i have figured out how to actually click on a cell in the puzzle and have it highlight but I cant seem to find a method to actually choose a particular cell and change its font/color(eg. table.getCell(1,5)). If I can find a way to do this I should be sorted. – Timmjy Morrissey Nov 27 '12 at 15:15
  • 2
    be sure to read the chapter on how to use JTable in the online tutorial referenced in the [swing tag wiki](http://stackoverflow.com/tags/swing/info) - it explains exactly what/how to do it – kleopatra Nov 27 '12 at 15:21
  • [How to Use Tables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html) – user1329572 Nov 27 '12 at 15:21

1 Answers1

2

In this example using JList, a ListSelectionModel.MULTIPLE_INTERVAL_SELECTION permits non-contiguous selections. You can use addSelectionInterval() in the ListSelectionModel to highlight the letters of your chosen word. You can enhance the display in your implementation of ListCellRenderer.

JTable uses the same ListSelectionModel; it uses a TableCellRenderer, rather than a ListCellRenderer, but the concept is the same.

As a word search puzzle need not be editable, either JTable or JList may be a suitable view.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045