BASIC / CATATAN</>↗Basic26 Sep 2010
The exceptions that you catch in a try-catch block must have been raised by a method that you’ve called. You can raise an exception with a statement that consists of the throw keyword, followed by an exception object. This exception object is an instance of any subclass of the Throwable class. In the example below […]
BASIC / CATATAN</>↗Basic25 Sep 2010
If a try block can throw several kind of exceptions, and you want to handle each exception differently, you can put several catch blocks to handle it. package org.kodejava.basic; public class MultipleCatchExample { public static void main(String[] args) { int[] numbers1 = {1, 2, 3, 4, 5}; int[] numbers2 = {1, 2, 3, 4, 5, […]
BASIC / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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. […]