Java table & list

Java table & list

I am taking string elements from user in list, And I want those list elements to be added to table row one by one, The jTable & list are at different classes but under same package. How to do so? Please Help me..

View Answers

April 2, 2011 at 12:48 PM

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.table.*;

class JListJTable{
    static int i=0;
    public static void main(String[] args){
    Vector v=new Vector();
    for(int i=1;i<=5;i++){
    String st=JOptionPane.showInputDialog(null,"Enter list values:");
    v.add(st);
    }
    String data[][] = {{}};
    String col[] = {"ID","List Elements"};
    final DefaultTableModel model = new DefaultTableModel(data,col);
    JTable table = new JTable(model);
    JScrollPane pane=new JScrollPane(table);
        JList list=new JList(v);

        ListSelectionListener listSelectionListener = new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
        boolean adjust = listSelectionEvent.getValueIsAdjusting();
        if(!adjust){
            i++;
          JList l = (JList) listSelectionEvent.getSource();
          Object selected = l.getSelectedValue();
          String st=selected.toString();
          System.out.println(selected.toString());
          model.insertRow(i,new Object[]{new Integer(i),st});
         }

       }
    };
    list.addListSelectionListener(listSelectionListener);
        JFrame f=new JFrame();
        f.add(list,BorderLayout.NORTH);
        f.add(pane,BorderLayout.SOUTH);
        f.setVisible(true);
        f.pack();
    }
}

April 2, 2011 at 12:48 PM

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.table.*;

class JListJTable{
    static int i=0;
    public static void main(String[] args){
    Vector v=new Vector();
    for(int i=1;i<=5;i++){
    String st=JOptionPane.showInputDialog(null,"Enter list values:");
    v.add(st);
    }
    String data[][] = {{}};
    String col[] = {"ID","List Elements"};
    final DefaultTableModel model = new DefaultTableModel(data,col);
    JTable table = new JTable(model);
    JScrollPane pane=new JScrollPane(table);
        JList list=new JList(v);

        ListSelectionListener listSelectionListener = new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
        boolean adjust = listSelectionEvent.getValueIsAdjusting();
        if(!adjust){
            i++;
          JList l = (JList) listSelectionEvent.getSource();
          Object selected = l.getSelectedValue();
          String st=selected.toString();
          System.out.println(selected.toString());
          model.insertRow(i,new Object[]{new Integer(i),st});
         }

       }
    };
    list.addListSelectionListener(listSelectionListener);
        JFrame f=new JFrame();
        f.add(list,BorderLayout.NORTH);
        f.add(pane,BorderLayout.SOUTH);
        f.setVisible(true);
        f.pack();
    }
}

April 3, 2011 at 1:04 AM

this is right..... But not that i want... I cant pass parameter to the class where table is, from the class where my list is. How to access list elements of one class in other class. N.T. I am using Netbeans. thanx...









Related Tutorials/Questions & Answers:
Java table & list
Java table & list  I am taking string elements from user in list, And I want those list elements to be added to table row one by one, The jTable & list are at different classes but under same package. How to do so? Please
ModuleNotFoundError: No module named 'jirafs-list-table'
ModuleNotFoundError: No module named 'jirafs-list-table'  Hi, My... named 'jirafs-list-table' How to remove the ModuleNotFoundError: No module named 'jirafs-list-table' error? Thanks   Hi, In your
Advertisements
table in java
table in java  Could any one make compiler in java please reply me
table in java
table in java  Could any one make compiler in java please reply me
table in java
table in java  Could any one make compiler in java please reply me
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?
How to solve this java code by adding the student marks not in the list...; marks >= 100) { data[a].setGrade("Not in the list of the table...++; } if (g.equals("Not in the list of the table")){ count12
table in java
table in java  please l want to make table and insert by user
how to display data in List Or grid or in table in Jsp
how to display data in List Or grid or in table in Jsp   <%@page... String P Value in List GIrd or Table please help am able to Print display data...="java.io.IOException"%> <%@ page language="java" contentType="text/html
how to send email list of email address through in database table list
how to send email list of email address through in database table list  package com.com; import java.io.IOException; import java.io.PrintWriter; import java.sql.PreparedStatement; import java.sql.ResultSet; import
How to add dropdown list in a row of a sort table applet?
How to add dropdown list in a row of a sort table applet?  How to add dropdown list in a row of a sort table applet
retrieve Dept Name from table dept and retrieve list of employee from emp table for that dept in combobox
retrieve Dept Name from table dept and retrieve list of employee from emp table... table dept(select deptno,deptname from dept where deptno=10) and retrieve list... the same input paramter then its should retrieve the data from another table
Time Table in Java
Time Table in Java  Hi, Deepak i am developing a time table for a school on java,but i am confuse how to start so please give me idea about
Java Hash table
Java Hash table   Hi I have to create code to allow the insertion of a sequence of numbers into a hash table,using a fixed size hash table. Then i... of numbers; insert these into the hash table. Can anyone give me any help
Create a Table - Java Beginners
Create a Table in Java  How can i create table in Java?  Java Example Code - Creating table in JAVA- - - - - - - - - - - - - - - - - - - - - - Hi, here i am giving you a java program code, that creates a table with two
Java Table Create
Java Table Create  hi........ thanks 4 ur reply......... but i... the following is the table Jan Feb Mar........... pH 2 3 4....... values also. I want that pH, temp etc should also come in that table
table
table  multiplicatyion table
table
table  Hi..I have a list of links which links to a table in the same page.If I click first link the table is displayed at the top, likewise if i click the last link the table is displayed at the last,i dont know how to set
creation of table using a Java swing
creation of table using a Java swing  how to create a table dynamically in Java swing
java coding for creating table in the console
java coding for creating table in the console  write a java program to create table
TABLE
TABLE   Why doesn't <TABLE WIDTH="100%"> use the full browser width
Table
Table  How i generate table in showMessageDialog. I want that i creat a table and run in showMessageDialogeprint("cprint("code sample");ode sample
Table
Table  How I generate table in showMessageDialog. E.g 3X1=3 3X2=6 3X3=9print("code sample
Table
Table  How i generate table in showMessageDialog. I want to creat a table and run in showMessageDialoge. Pl make a table programe which run..., JOptionpane, Integer.parseInt. Please use only these above methods to make table
table
input from oracle table(my database table..) This is a very important table of my
Table
Table  How i generate table in JOptionpane.showMessageDialog... advance coding but i want u make the table using JOptionpane.showMessageDialog, import.javax.swing int Integer.parseInt(). Thats my limit. Pl generata a table
table?
table?  Hi, how could i make a table in javascript, which would look like this: AA CODON Number /1000 Fraction .. (this row... can't figure out, how to construct a table,with two fixed columns, one that reads
Java list
Java list  What is the difference between a Choice and a List
Table
Table  Why u dont understand sir?? I want to make a table program which generate a table on showMessageDialog. I have learnt these methods until now... methods to be used. Write a table program which use only and only these above methods
Table
Table  How i create table on showMessageDialog using JOptionpane and Integer.parseInt. No other method to use. Pl make a program which generate 5X1=5 5X2=10 5X3=15   Hi Friend, Try this: import javax.swing.*; import
How to add dynamic table in java
How to add dynamic table in java  How to add dynamic table in java...(); } catch(Exception e){ System.out.println(e); } JTable table = new JTable(data...); } JScrollPane scrollPane = new JScrollPane( table ); p.add( scrollPane ); JFrame f=new
List In Java
List In Java In this section we will read about the List data structure in Java and how the List data structure can be implemented in Java. List data structure is implemented in Java using List interface. List interface allows
Table width - Java Interview Questions
Table width  Hello sir, I want the result for table content display on some fixed size in long letter. For eg: roseindia.net is a one field, output display on roseindia .net id name address 1
Pls provide me jsp code to get values in drop down list from another table's field....
Pls provide me jsp code to get values in drop down list from another table's field....  my project has customer registration and company registration pages..... when i insert data in company registration .. it ll have company id
Add/Remove Rows Dynamically with drop down list in html table using php
Add/Remove Rows Dynamically with drop down list in html table using php  Here Is My Code. I want to give and get the id of drop down list. Can Anyone...;table border="1" id="tblSample"> <tr> <
Version of com.qiukeke>console-table dependency
List of Version of com.qiukeke>console-table dependency
create table in mysql of split file created in java
create table in mysql of split file created in java  i have created splite file in java. now i want to create table from splited data how to do
java program(Hash Table) - Java Beginners
java program(Hash Table)  Store the names of 10 major cities and the names of corresponding countries in a hash table. Accept the name of a city... argument or specifies a city that is not in the hash table.  Hi friend
Searching a tex on a table in java! - Java Beginners
Searching a tex on a table in java!  i have a table which contains several data. using a textfield the item hat i search must be selected... the problem. For more information on Java visit to : http://www.roseindia.net
how to draw a table on jframe in java - Java Beginners
how to draw a table on jframe in java  how to draw a table on jframe in java?  Hi friend, import java.awt.*; import...", "MCA" } }; Object headers[] = { "Upper", "Lower" }; JTable table
List
List  i do have one list object, i want to compare this list from database table and if match found i want to update the list
how to display a table and buttons in swings - Java Beginners
how to display a table and buttons in swings  Hi frends, Actually i want to display a table during runtime and at the same time i also want to add different buttons below this displayed table using swings.....please can any
Java list of uninstantiated classes
Java list of uninstantiated classes  Java list of uninstantiated classes
Simple Hash Table implementation in Java
Simple Hash Table implementation in Java       This section describes the complete Hash Table implementation from the basic in Java. In this section, you will see how
java technologies list
java technologies list  Please provide me the java technologies list
Does java supports queries with references/Table alias?
Does java supports queries with references/Table alias?  Hello, I have an Oracle query:SQL> select t.TopicName, p.NumberofPolls from EMSTopic t,EMSPoll p where t.TopicID = p.TopicID and t.TopicName= 'Sybase'; which
is list ordered in java
is list ordered in java  Hi, I want to use the list in Java... wanted to know is list ordered in Java? So, Let's know if list ordered in Java? Thanks   About the List Interface in Java The List interface
is list ordered in java
is list ordered in java  Hi, I want to use the list in Java... wanted to know is list ordered in Java? So, Let's know if list ordered in Java? Thanks   About the List Interface in Java The List interface
is list ordered in java
is list ordered in java  Hi, I want to use the list in Java... wanted to know is list ordered in Java? So, Let's know if list ordered in Java? Thanks   About the List Interface in Java The List interface
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner.../operations on two or more operands. Here is the list of operator in Java
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner.../operations on two or more operands. Here is the list of operator in Java

Ads