Android Open Source - MobileDev_beginner List Test






From Project

Back to project page MobileDev_beginner.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project MobileDev_beginner listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * @(#)ListTest.java/*from w ww  . j a v  a 2s . co  m*/
 *
 *
 * @author
 * @version 1.00 2014/7/14
 */
import java.awt.*;
//import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class ListTest extends JFrame {
  private JList colorList;
  private Container container;

  private final String colorNames[] = { "Black", "Blue", "Cyan", "Dark Gery", "Grey", "Green", "Light Grey", "Magenta", "Orange", "Pink", "Red", "White", "Yellow" };

  private final Color colors[] = { Color.BLACK, Color.BLUE, Color.CYAN, Color.DARK_GRAY, Color.GRAY, Color.GREEN, Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE, Color.PINK, Color.RED, Color.WHITE, Color.YELLOW };

  //set GUI
    public ListTest() {
      super("List Test");

      //get content pane and set layout
      container = getContentPane();
      container.setLayout(new FlowLayout() );

      //create a list with items in colorNames array
      colorList = new JList(colorNames);
      colorList.setVisibleRowCount(5);

      //not allow multiple selection
      colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      //add JScrollPane contain JList to content pane
      container.add( new JScrollPane( colorList));
      colorList.addListSelectionListener(
        new ListSelectionListener() { //inner class
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          //handle list selection events
          public void valueChanged(ListSelectionEvent event) {
            container.setBackground ( colors [ colorList.getSelectedIndex() ]);
          }
        } //end inner class

      ); //end call to addListSelectionListener

      setSize(350, 150);
      setVisible( true);
    }

    public static void main (String args[]) {
      ListTest app = new ListTest();
      app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
    }
}




Java Source Code List

.CheckBoxTest.java
.Demo.java
.ListTest.java
.OurServlet.java
.TextFieldTest.java
com.corruptor.smssender.smsMenu.java
com.example.login.insidemenu.java
com.example.login.loginact.java
org.corruptor.Booking.java
org.corruptor.Car.java
org.corruptor.Customer.java
org.corruptor.Login.java
org.corruptor.Menu.java
org.corruptor.MyConnection.java
org.corruptor.MyMain.java
org.corruptor.MyScanner.java
org.corruptor.Reports.java