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...

Ads









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
table in java
table in java  Could any one make compiler in java please reply me
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  please l want to make table and insert by user
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
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
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
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
Java Table Create
Java Table Create  hi........ thanks 4 ur reply......... but i... and then avalues in front of them. Eg: suppose the following is the table..., temp etc should also come in that table............. so plz tel me how
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
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  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
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
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
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
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> <
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
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
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
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
Java to create table in jsp file that include other jsp file
Java to create table in jsp file that include other jsp file  String jspContent = "table" += "tr" += "td" += "jsp:include page='fileSource'" //this line is not working properly... += "/td" += "/tr>" += "/table" Please refer
Convert the excel sheet data into oracle table through java or jsp
Convert the excel sheet data into oracle table through java or jsp  Hi Friends, Let me help this issue i am phasing Convert the excel sheet data into oracle table through java or jsp
how to update values of a html form into an excel table using java servlets?
how to update values of a html form into an excel table using java servlets?  i have written a java servlet program, which has a html form... be loaded into an excel table automatically. i have created a dsn for excel
how to load values of html form into an excel table using java servlet?
how to load values of html form into an excel table using java servlet?   i have written a java servlet program, which has a html form to be filled... be loaded into an excel table automatically. i have created a dsn for excel table
Version of com.seancheatham>graph-big-table-adapter_2.11 dependency
List of Version of com.seancheatham>graph-big-table-adapter_2.11 dependency
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
Storing records of a file inside database table in java
Storing records of a file inside database table in java  Here is my requirement, I have a file which contains some number of records like this student.csv 1 sid sname age 2 1 suresh 24 3 2
Java list of uninstantiated classes
Java list of uninstantiated classes  Java list of uninstantiated classes
java technologies list
java technologies list  Please provide me the java technologies list
Table Creation
Table Creation  hi! I want a table which looks like following can u tell me how it can be made with java swings.. YEAR 2005 Jan Feb... to make such table? plz help.........  
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