JavaSwingComponents: Displaying list data


Displaying list data

A study of inconsistencies in Swing.

JList

JTable

JTree

Data setup

ListModel

ListModel -> TableModel wrapper

or TableModel from the beginning

possible to use multiple-column TableModel by putting only a one column into the TableColumnModel

ListModel -> TreeModel (only root with children) wrapper

or TreeModel from the beginning

TreeModel has a different set of events (no replace, but arbitrary adding/removal)

No multiple equal items.

Items must be immutable.

Component setup

no header

hide root

Wrapping

(though it distorts the idea of ordered data)

yes (1.4)

no

no

Cell bounds

based on width/height pixel values

based on a prototype

based on renderer preferred size

always based on width/height pixel values

columns may be horizontally resized if not enough space (depending on auto resize mode)

width based on preferred renderer width

height based on pixel values or preferred renderer height

cells are not grown to have all the same width

Spacing between cells

no

yes

no

Grid between cells

no

yes (but somewhat broken)

maybe (not generally configurable)

Selection

easily configurable (allow, change behaviour), possibly confusing

User selection

broken

better (mouse dragging, change of anchor cell)

different

User editing

no

yes (each cell maybe editable or not)

yes (less than JTable, partly better?)

Border support

yes

no (bug)

yes

Selection color management

yes

yes

no

Tool tip based on renderer

yes (1.4)

yes

yes

Default renderer problems

always paints background

1.3: background painting needed care

color configuration doesn't handle LAF switching

always paints background (not even in the

JTree's color), low level paint code

doesn't handle LAF switching

Overhead

cell size management needs memory

column layout needs time

possibly high (converting rows/paths/bounds)

Special

  • won't be higher than its cells (by default)

  • numerous bugs

  • no getNextMatch (simple keyboard management)


(C) 2001-2009 Christian Kaufhold (swing@chka.de)