SWING / NOTES</>↗Swing21 Sep 2010
This program shows you how to select some rows in the JTable programmatically. Below we demonstrate how to select rows using the setRowSelectionInterval() method, remove or clear row selection using removeRowSelectionInterval() method and use the addRowSelectionInterval() to add more rows to the previously selected rows. package org.kodejava.swing; import javax.swing.*; import javax.swing.table.AbstractTableModel; import java.awt.*; public class […]
BASIC / NOTES</>↗Basic20 Sep 2010
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions. When an abnormal situation occurs within a method, an Exception object is thrown. This object contains information about the error or unusual problems that occur. Creating an exception object and handing it to […]
SWING / NOTES</>↗Swing20 Sep 2010
There are three selection modes available in the JTable component. The selection mode can be a single selection, a single interval selection or a multiple interval selection. To set the selection mode we call the JTable.setSelectionMode() method and pass one of the following value as the parameter: ListSelectionModel.SINGLE_SELECTION ListSelectionModel.SINGLE_INTERVAL_SELECTION ListSelectionModel.MULTIPLE_INTERVAL_SELECTION package org.kodejava.swing; import javax.swing.*; im...
SWING / NOTES</>↗Swing20 Sep 2010
To allow a row selection or a column selection or both row and column selection in JTable component we can turn it on and off by calling the JTable‘s setRowSelectionAllowed() and JTable‘s setColumnSelectionAllowed() methods. Both of these methods accept a boolean value indicating whether the selection is allowed or not allowed. Setting both of them […]
SWING / NOTES</>↗Swing19 Sep 2010
Each column of a JTable component is represented by the TableColumn class. The method for setting or changing the width of the column includes the setMinWidth(), setMaxWidth() and setPreferredWidth(). These methods are used to set the minimum, maximum and the preferred width of the column respectively. When we set only the preferred width of a […]
SWING / NOTES</>↗Swing19 Sep 2010
Another way to create and configure a JTable component is using a table model. A table model is more preferred to using array or vector as the data source for the table. The simplest way to create a table model is by extending the AbstractTableModel abstract class which implements the TableModel interface. The AbstractTableModel implements […]