Java table & list

Ads

 
 

Share on Google+Share on Google+

Amol T Kokane
Java table & list
3 Answer(s)      6 years and 6 months ago
Posted in : Java Beginners

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

Ads
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
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
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
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
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... 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
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
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
Java list
Java list  What is the difference between a Choice and a List
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
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
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
Java list of uninstantiated classes
Java list of uninstantiated classes  Java list of uninstantiated classes
table
table  multiplicatyion table
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
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
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
java technologies list
java technologies list  Please provide me the java technologies list
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
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
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

Ads

 
Advertisement null

Ads