This program demonstrates the split pane component organizer. : Splitpane « Swing JFC « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Swing JFC » SplitpaneScreenshots 
This program demonstrates the split pane component organizer.
This program demonstrates the split pane component organizer.
 
/*
   This program is a part of the companion code for Core Java 8th ed.
   (http://horstmann.com/corejava)

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * This program demonstrates the split pane component organizer.
 @version 1.03 2007-08-01
 @author Cay Horstmann
 */
public class SplitPaneTest
{
   public static void main(String[] args)
   {
      EventQueue.invokeLater(new Runnable()
         {
            public void run()
            {
               JFrame frame = new SplitPaneFrame();
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               frame.setVisible(true);
            }
         });
   }
}

/**
 * This frame consists of two nested split panes to demonstrate planet images and data.
 */
class SplitPaneFrame extends JFrame
{
   public SplitPaneFrame()
   {
      setTitle("SplitPaneTest");
      setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

      // set up components for planet names, images, descriptions

      final JList planetList = new JList(planets);
      final JLabel planetImage = new JLabel();
      final JTextArea planetDescription = new JTextArea();

      planetList.addListSelectionListener(new ListSelectionListener()
         {
            public void valueChanged(ListSelectionEvent event)
            {
               Planet value = (PlanetplanetList.getSelectedValue();

               // update image and description

               planetImage.setIcon(value.getImage());
               planetDescription.setText(value.getDescription());
            }
         });

      // set up split panes

      JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, planetList, planetImage);

      innerPane.setContinuousLayout(true);
      innerPane.setOneTouchExpandable(true);

      JSplitPane outerPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, innerPane,
            planetDescription);

      add(outerPane, BorderLayout.CENTER);
   }

   private Planet[] planets = new Planet("Mercury"24400)new Planet("Venus"60520),
         new Planet("Earth"63781)new Planet("Mars"33972),
         new Planet("Jupiter"7149216)new Planet("Saturn"6026818),
         new Planet("Uranus"2555917)new Planet("Neptune"247668),
         new Planet("Pluto"11371)};
   private static final int DEFAULT_WIDTH = 300;
   private static final int DEFAULT_HEIGHT = 300;
}

/**
 * Describes a planet.
 */
class Planet
{
   /**
    * Constructs a planet.
    @param n the planet name
    @param r the planet radius
    @param m the number of moons
    */
   public Planet(String n, double r, int m)
   {
      name = n;
      radius = r;
      moons = m;
      image = new ImageIcon(name + ".gif");
   }

   public String toString()
   {
      return name;
   }

   /**
    * Gets a description of the planet.
    @return the description
    */
   public String getDescription()
   {
      return "Radius: " + radius + "\nMoons: " + moons + "\n";
   }

   /**
    * Gets an image of the planet.
    @return the image
    */
   public ImageIcon getImage()
   {
      return image;
   }

   private String name;
   private double radius;
   private int moons;
   private ImageIcon image;
}

   
  
Related examples in the same category
1.Create a left-right split pane
2.Create a top-bottom split pane
3.A quick test of the JSplitPane classA quick test of the JSplitPane class
4.SplitPane Demo 2
5.Swing SplitPane SampleSwing SplitPane Sample
6.Resize SplitPaneResize SplitPane
7.SplitPane: VerticalSplitSplitPane: VerticalSplit
8.SplitPane Sample 3SplitPane Sample 3
9.Property SplitProperty Split
10.Use the split paneUse the split pane
11.Continuously move the divider and resize its child components while the user is dragging the divider
12.Getting the Setting the Children in a JSplitPane Container
13.Getting and Setting the Divider Location in a JSplitPane Container
14.Distributing Space When a JSplitPane Container Is Resized
15.The split pane supports a one-touch-expandable capability that allows the user to conveniently move the divider to either end with a single click
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.