devdaily home | java | perl | unix | directory | blog

What this is

This file is part of the Tame Swing collection that we have compiled. All of the Java source code in these examples was created by Nobuo Tamemasa. As these examples have become hard to find on the internet, we have put them in one place here, supported by minimal advertising. In time we will include images of each running sample Java/Swing application.

The intent of having these files here is to help you learn Java and Swing by example, and Tame certainly created some terrific examples of the power of the Swing framework.

Other links


java, swing, example, sample, source, custom, group, check, checkbox, title, titled, form

The source code

/* (swing1.1.1)*/
package tame.examples;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

import tame.panel.CompTitledPane;

@author Nobuo Tamemasa
@version 1.0 08/13/99
public class CompTitledPaneExample3 extends JFrame {

  public CompTitledPaneExample3() {

    Container c = getContentPane();
    c.setLayout(new GridLayout(2,2));
    ButtonGroup group = new ButtonGroup();
    APanel p = new APanel(group, "Metal");
    c.add(new APanel(group, "Motif"));
    c.add(new APanel(group, "Mac"));
    c.add(new APanel(group, "Windows"));

  class APanel extends CompTitledPane {
    JRadioButton titleComp;

    APanel(ButtonGroup group, final String text) {
      titleComp = new JRadioButton(text);
      final JButton button = new JButton(text);
      //this.titleComp = titleComp;
      titleComp.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
          button.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
      button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

    public JRadioButton getRadioButton() {
      return titleComp;

  public static void main (String args[]) {
    CompTitledPaneExample3 frame = new CompTitledPaneExample3();
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
    frame.setSize(280, 200);

Copyright 1998-2009
All Rights Reserved.