Archive for the ‘Swing’ Category

How do I get a JScrollPane to always display scroll bars?

Java, Swing, Tip 6.11.2015 No Comments

You can achieve this by setting the scroll bar policy on both the verical and horizontal scroll bars.

Read More

How to control decimal places displayed in JTable column?

Java, Swing 10.9.2015 No Comments

Rendering of table cells is handled by instances of TableCellRenderer. By default JTable uses a DefaultTableCellRenderer to render all of its cells. To control the number of decimal places used we just need to subclass DefaultTableCellRenderer and format the cell double value before passing the (formatted) value to to the parent (DefaultTableCellRenderer) class. To get…

Read More

How do add a checkbox to items in a JList?

Java, Swing, Tip 30.6.2015 1 Comment

We often get asked about how to implement a list of checkboxes using Swing. Using a JList filled with JCheckbox’s seems the obvious solution, however JList does not support cell editors so this does not work. One possible solutions is to use a single column JTable and store boolean’s as the cell value (the default…

Read More

Convert Inches to Centimetres

Java, Swing 14.10.2011 No Comments
Convert Inches to Centimetres

The next example was kindly shared by one of our members. She had a Java Swing assignment to create a Swing GUI for converting Inches to Centimetres and had no idea where to start. We helped her break down the problem and come up with a solution. The resulting code can be found below.

Read More

Calculator Keypad

Java, Swing 14.8.2010 No Comments

This problem involves understanding some of the basics of building a Swing application including how individual components are laid out inside a window, and how your application can react to the user interacting with the application. In this case we need to update a text field whenever a button is pressed. The key points to…

Read More
s2Member®