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

Keywords/tags

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

The source code

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

import java.awt.BorderLayout;
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.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import tame.panel.CompTitledPane;
import tame.panel.StateTransmitter;

/**
@author Nobuo Tamemasa
@version 1.0 08/12/99
*/
public class CompTitledPaneExample2 extends JFrame {

  public CompTitledPaneExample2() {
    super("CompTitledPaneExample2");
    JCheckBox title = new JCheckBox("Title");
    title.setSelected(true);
    final CompTitledPane p1 = new CompTitledPane(title);
    title.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        p1.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
      }
    });
    APanel p2 = new APanel();
    p1.setTransmittingAllowed(true);
    p1.setTransmitter(p2);
    p1.getContentPane().add(p2);
    getContentPane().add(p1, BorderLayout.CENTER);
  }

  class APanel extends JPanel implements StateTransmitter {
    JButton    button;
    JTextField textField;

    APanel() {
      button = new JButton("abc");
      button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          System.out.println("Ouch!");
        }
      });
      textField = new JTextField(10);
      textField.setText("text");
      add(button   , BorderLayout.NORTH);
      add(textField, BorderLayout.SOUTH);
    }

    public void setChildrenEnabled(boolean enable) {
      button.setEnabled(enable);
      textField.setEnabled(enable);
    }
  }

  public static void main (String args[]) {
    CompTitledPaneExample2 frame = new CompTitledPaneExample2();
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
	System.exit(0);
      }
    });
    frame.setSize(280, 110);
    frame.setVisible(true);
  }
}