Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 22nd, 2003, 09:34 AM
Authorized User
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to egolileopablo Send a message via Yahoo to egolileopablo
Default help me add, delete from a JList in a Vector

help me add, delete from a JList in a Vector
try this code and fix how to add to the JList through a vector and delete from
the JList through the vector.
this the code below

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.*;
public class TabPane extends JFrame {

    JTabbedPane tabpane = new JTabbedPane(JTabbedPane.TOP);
    private Vector vector = new Vector(0);
    //String[] data = {"2D","3B", "12C", "47E", "47F", "Shiva", "Sammuel",
"Daniel", "William", "Horatio", "Biney", "Theodore"};
    //private JList dataList = new JList();//data);
    //Component panel;
    public TabPane() {
      super("Blue Star Airlines");

      Component panel = textPanel("View");
      tabpane.addTab("View", panel);

      Component panel1 = textPane("Add");
      tabpane.addTab("Add", panel1);

      getContentPane().add(tabpane, new BorderLayout().NORTH);

      setLocation(100, 100);


    protected Component textPanel(String str) {

      getContentPane().setLayout(new GridLayout(1,1));

      JPanel allPanel = new JPanel();

      JPanel listPanel = new JPanel();

      Box box = new Box(BoxLayout.Y_AXIS);

      String[] data = {"2D","3B", "12C", "47E", "47F", "Shiva", "Sammuel",
"Daniel", "William", "Horatio", "Biney", "Theodore"};
      final JList dataList = new JList(data);
      dataList.setSelectionMode(ListSelectionModel.SINGL E_SELECTION);
      dataList.addListSelectionListener(new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent sevent) {

      JScrollPane scrollPane = new JScrollPane();
      listPanel.add(box, new BorderLayout().WEST);

      JPanel pane = new JPanel();
      pane.setLayout(new GridLayout(0,2));

      JLabel slabel = new JLabel("Seat No");
      final JTextField sfield = new JTextField(15);

      JLabel nlabel = new JLabel("Name");
      final JTextField nfield = new JTextField(15);

      JLabel plabel = new JLabel("Price");
      final JTextField pfield = new JTextField(15);

      JPanel boxPanel = new JPanel();
      Box cbox = new Box(BoxLayout.X_AXIS);
      JCheckBox check = new JCheckBox("Priority");

      final JButton abtn = new JButton("Delete");
      abtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
      if (event.getSource() == abtn)
      JOptionPane.showMessageDialog(null, "Data Deleted");

      allPanel.add(listPanel, new BorderLayout().WEST);
      allPanel.add(pane, new BorderLayout().CENTER);
      allPanel.add(boxPanel, new BorderLayout().SOUTH);

      return allPanel;

     protected Component textPane(String str) {
      final JLabel statusLabel = new JLabel();
      statusLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));
      JPanel paneall = new JPanel();

      JPanel dpane = new JPanel();
      dpane.setLayout(new GridLayout(0,2));
      JLabel slabel = new JLabel("Seat No");
      final JTextField sfield = new JTextField(10);

      JLabel nlabel = new JLabel("Name");
      final JTextField nfield = new JTextField(10);

      JLabel plabel = new JLabel("Price");
      final JTextField pfield = new JTextField(10);

      JPanel pan = new JPanel();

      JPanel checkPanel = new JPanel();
      //checkPanel.setLayout(new GridLayout(0,2));

      Box checkBox = new Box(BoxLayout.Y_AXIS);
      JCheckBox check = new JCheckBox("Business Class");
      pan.add(checkPanel, new BorderLayout().WEST);

      JPanel buttonPanel = new JPanel();
      Box buttonBox = new Box(BoxLayout.Y_AXIS);
      final JButton abtn = new JButton("ADD");
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {

            if (event.getSource() == abtn ) {

            //Object ob = vector.set(20, sfield.getText());
            //dataList = (JList)ob;
            sfield.setText( "" );
            nfield.setText( "" );
            pfield.setText( "" );

            JOptionPane.showMessageDialog(null, "Data Stored");


            else if (event.getSource() == abtn ) {
                  JOptionPane.showMessageDialog(null, "Enter seat number");
            else if (nfield.getText().equals(""))
              JOptionPane.showMessageDialog(null, "Enter seat number");
            else if (pfield.getText().equals(""))
                  JOptionPane.showMessageDialog(null, "Enter seat number");

      JButton cbtn = new JButton("Cancel");
      cbtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {

      buttonPanel.add(statusLabel, new BorderLayout().SOUTH);
      pan.add(buttonPanel, new BorderLayout().EAST);

      paneall.add(dpane, new BorderLayout().NORTH);
      paneall.add(pan, new BorderLayout().SOUTH);

      return paneall;


    public static void main(String args[]) {
      JPasswordField field = new JPasswordField();
      JOptionPane.showInputDialog(null, "Enter Username:", field.getPassword());
      JOptionPane.showInputDialog(null, "Enter Password:");
      if (field.getText().equals("")) {

        JOptionPane.showInputDialog(null, "Enter Username:",
        JOptionPane.showInputDialog(null, "Enter Password:");
      TabPane tab = new TabPane();


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Node add/delete aintvoguish XSLT 2 December 20th, 2007 03:01 AM
vector.add(); -- Reference or Object? Firedawn Servlets 2 February 23rd, 2005 01:04 AM
Edit/Add/Delete within a DataGrid ozzy VB.NET 2002/2003 Basics 5 January 23rd, 2005 01:17 AM
help add, delete from a JList in a Vector egolileopablo J2EE 1 January 1st, 2005 06:16 AM
vector.add(); chikodi Servlets 2 October 23rd, 2003 02:03 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.