CODEFETCH™
            Examples
Cache of PJUI/com/marinilli/b1/c3/spareparts/SparePartViewer.java from
http://www.marinilli.com/books/b1/PJUI.zip
Source code below from:
Professional Java User Interfaces
By Mauro Marinilli
Published 26 May, 2006
Average rating

      Powells     Alibris


package com.marinilli.b1.c3.spareparts;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.awt.*;
import com.marinilli.b1.c15.util.ui.*;
import com.marinilli.b1.c7.ServiceManager;

/**
 * Example of a GUI Prototype
 *
 * @author Mauro Marinilli
 * @version 1.0
 */
public class SparePartViewer extends JFrame{
  JTree tree;

  public SparePartViewer() {
    setIconImage(ServiceManager.getImageIcon(
                  Commands.TOOLBAR_GEN_PATH + "ComposeMail24.gif").getImage());
    JPanel main = new JPanel(new BorderLayout());

    JSplitPane vSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    JSplitPane hSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    vSplit.setTopComponent(hSplit);
    vSplit.setBottomComponent(new DetailPanel());
    hSplit.setLeftComponent(getTreePanel());

    hSplit.setRightComponent(new SPTable().attach());

    main.add(vSplit,BorderLayout.CENTER);
    main.add(new JLabel("select a part "),BorderLayout.SOUTH);
    getContentPane().add(main);
    setTitle("Spare Parts - View  [Prototype]");
    addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    setJMenuBar(getMenu());
    pack();
    setVisible(true);
    ServiceManager.setMainFrame(this);
    setSize(new Dimension(640,480));
  }

  private JMenuBar getMenu() {
    JMenuBar jMenuBar = new JMenuBar();
    jMenuBar.add(new JMenu("File"));
    jMenuBar.add(new JMenu("Edit"));
    jMenuBar.add(new JMenu("View"));
    jMenuBar.add(new JMenu("Catalog"));
    jMenuBar.add(new JMenu("Windows"));
    jMenuBar.add(new JMenu("Help"));
    return jMenuBar;
  }

  private JScrollPane getTreePanel(){
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
    DefaultMutableTreeNode a11 = new DefaultMutableTreeNode("Motor");
    DefaultMutableTreeNode a12 = new DefaultMutableTreeNode("Mechanics");
    DefaultMutableTreeNode a13 = new DefaultMutableTreeNode("Electronics");
    DefaultMutableTreeNode a14 = new DefaultMutableTreeNode("Bulk");
    DefaultMutableTreeNode a15 = new DefaultMutableTreeNode("other");
    root.add(a11);
    root.add(a12);
    root.add(a13);
    root.add(a14);
    root.add(a15);
    DefaultMutableTreeNode a121 = new DefaultMutableTreeNode("Top");
    DefaultMutableTreeNode a122 = new DefaultMutableTreeNode("Bottom");
    DefaultMutableTreeNode a123 = new DefaultMutableTreeNode("Chassis");
    a12.add(a121);
    a12.add(a122);
    a12.add(a123);
    a11.add(new DefaultMutableTreeNode("..."));
    a13.add(new DefaultMutableTreeNode("..."));
    a14.add(new DefaultMutableTreeNode("..."));
    a15.add(new DefaultMutableTreeNode("..."));

    tree = new JTree(root);

    JScrollPane jp = new JScrollPane(tree);
    return jp;
  }

  public static void main(String[] args) {
    SparePartViewer s = new SparePartViewer();
  }

}