13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

16.7 Getting Down to Cases: Designing a GUI for BudgetPro365JLabel retval = new JLabel();// ...if (row == 2) {retval.setBackground(Color.GREEN);} else {retval.setBackground(Color.WHITE);}return retval;The full implementati<strong>on</strong> of a renderer can also take into account whetheror not the cell is selected and/or has focus. This has to do with enabling mouseclicks to select either that particular cell or the row or column c<strong>on</strong>taining thatcell. You will likely want to render the cell differently (with a darker color,perhaps) to show that it has been selected. Whatever the renderer, you set upand then return a GUI comp<strong>on</strong>ent whose attributes (f<strong>on</strong>t, color, size, andso <strong>on</strong>) are used to display that cell.We hope you get the idea—there is a lot more to renderers than we willcover here. The Java Tutorial covers them more, and the Javadoc pages havesome introducti<strong>on</strong>, too.Similar to renderers are editors. When a user clicks in a table cell, the tablemay allow him or her to edit its c<strong>on</strong>tents. A cell editor is needed to do that,and then your program needs to do something with the value that was entered.For our BudgetPro example we avoid this complexity by disallowing the userto enter anything into the table—our table is for display <strong>on</strong>ly. We do this <strong>on</strong>lines 187–191 by overriding the method isCellEditable() to always returnfalse:187 public boolean188 isCellEditable(int row, int col)189 {190 return false;191 } // is CellEditableNotice that the method is passed the row and column means that youcould make some cells editable and some not.16.7.2.10 Selecti<strong>on</strong> ListenersLet’s look at the last part of the table that we implement for BudgetPro:194 list.setSelecti<strong>on</strong>Mode(ListSelecti<strong>on</strong>Model.SINGLE_SELECTION);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!