BASIC / NOTES</>↗Basic23 Sep 2010
The throws keyword is used in method declarations to specify which exceptions are not handled within the method body but rather passed to the next higher level of the program. All uncaught exceptions in a method that are not instances of RuntimeException must be declared using the throws keyword. In the example below you could […]
SWING / NOTES</>↗Swing22 Sep 2010
This program shows you how to select some columns in the JTable programmatically. Below we demonstrates how to select columns using the setColumnSelectionInterval() method, remove or clear column selection using removeColumnSelectionInterval() method and use the addColumnSelectionInterval() to add more columns to the previously selected columns. package org.kodejava.swing; import javax.swing.*; import javax.swing.table.AbstractTableModel; import java.awt.*; public class […]
SWING / NOTES</>↗Swing22 Sep 2010
To right-align numbers type of data in JTable cells we need to implements a TableModel. The TableModel‘s interface getColumnClass(int index) implementation return the class of the cell values, this information is used by JTable component to setup a default renderer and editor for the column. package org.kodejava.swing; import javax.swing.*; import javax.swing.table.AbstractTableModel; import java.awt.*; public class […]
SWING / NOTES</>↗Swing22 Sep 2010
To make a JTable renders a boolean as a checkbox in the table cell we need to tell the table that a cell stores a boolean type of data. To do this we have to implement a TableModel for the JTable component. TableModel‘s getColumnClass(int columnIndex) must return the type of data stored in a cell. […]
SWING / NOTES</>↗Swing21 Sep 2010
Disables or enables JTable‘s cell selection can be done by calling the setCellSelectionEnabled(boolean cellSelectionEnabled) method. This method accept a boolean value. Calling this method also changes the state of table’s row and column selection respectively. To completely remove the selection capability from JTable component we can change its focusable state to false by calling the […]
SWING / NOTES</>↗Swing21 Sep 2010
The following examples shows you how to get the selected rows or the selected columns or the selection of multiple cells in the JTable component. To listen for selection event we can add a selection listener to JTable component by calling the JTable.getSelectionModel().addListSelectionListener() method. This method accepts an object which implements a ListSelectionListener interface.` package […]