Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

swing



The swing package contains additional classes which work with the Java swing package.

JCloseableTabbedPane

The JCloseableTabbedPane class is a closeable tabbed pane. It is a JTabbedPane with a close button to close each tab.

Example:
closableTabbedPane

Generic dialog

Main Article: Swing GenericDialog

The GenericDialog class is a generic dialog component, with Yes / No buttons. The minimal method to implement is the GenericDialog.createPanel() method, which allows to create the main panel of the dialog.

Example:
genericdialog

Dialog builder

Main Article: Dialog builder

The DialogBuilder class simplifies the creation of popup dialogs, allowing to create several rows of content, optionally enclosed in their titled borders.

Example:
dialoginfomessage2

File choosers

Main Article: File choosers

Several classes extend the Swing JFileChooser class:

JColorSelector

The JColorSelector class is a JColorChooser backed by a component.

Example

  JFrame f = new JFrame("test");
  f.setSize(200, 300);
  JColorSelector cs = new JColorSelector(new DefaultColorSelectionModel());
  cs.setColor(Color.lightGray);

  cs.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      System.out.println("Action : ");
    }
  });

  f.getContentPane().setLayout(new FlowLayout());
  f.getContentPane().add(cs);
  f.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent e) {
      System.exit(0);
    }
  });
  f.pack();
  f.setVisible(true);
Result:
jcolorselector

JListChooser

The JListChooser class is a JList allowing to define a list of data, which can be added / removed / changed.

Example

  String[] fillValues = { "NONE", "HORIZONTAL", "VERTICAL VALUE", "BOTH" };
  JComboBox cb = new JComboBox(fillValues);
  cb.setSelectedItem("VERTICAL VALUE");

  ListChooserHandler handler = new ListChooserHandler() {
    @Override
    public Object getCurrentValue(JComponent c) {
      JComboBox cb = (JComboBox) c;
      return cb.getSelectedItem();
    }
  };
  JListChooser chooser = new JListChooser(cb, handler);

  chooser.setHandler(handler);
  chooser.setTitle("test");
  int retour = chooser.showDialog(null);
  if (retour == JListChooser.APPROVE_OPTION) {
    System.out.println("APPROVE: " + chooser.getValues().size());
  } else {
    System.out.println("CANCEL");
  }
Result:
jlistchooser

JMultilineTextEditor

Main Article: JMultilineTextEditor

The JMultilineTextEditor class is a JTextComponent backed by a small component which can be shown on one line.

jmultilinetexteditor
The text can be directly edited on the text field, or by editing a multiline dialog after clicking on the left button.
jmultilinetextdialog
Note that it is possible to customize the dialog itself by overriding the JMultilineTextEditor.createMultilineDialog() method.

JListSelector

The JListSelector class is a JListChooser backed by a component.

JMemoryViewer

Main Article: swing Memory viewer

The JMemoryViewer class is a component which shows the memory used by the program compared to the total memory available for the JVM.

Property editor

Main Article: swing property editor

The PropertyEditor class is a component which presents datas in a two-dimensional table format. It can be used to show and modify every types of properties.

There are only two columns in this Table:
  • the left column shows the name of the property to be shown
  • the right column shows the value of this property to edit. All editors managed by the ExtendedCellEditor class can be used
It extends the functionalities of the generic JTable component by allowing to:
  • add every type of editor / renderer for each row, providing that they are JComponents managed by the ExtendedCellEditor class


The process of the creation of a PropertyEditor must follow these rules: The component can then be used as any JPanel.

Note: Events fired by each rows are managed by the editor added in the row by the PropertyEditor.addProperty(JComponent, Object, String) method.

Extended Cell Editor

Main Article: Extended Cell Editor

The ExtendedCellEditor class allows to put custom components in JTable cells.

Layout utilities

Main Article: LayoutUtils

The LayoutUtils class propose some utilities for Swing Layouts which provide greedy Box fillers to use with the BoxLayout.

Categories: packages | swing

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences