Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java table & list

Have Programming Question? Ask it here!
 
 
 


Amol T Kokane
Java table & list
3 Answer(s)      3 years and 5 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..


Advertisement
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
Java list
Java list  What is the difference between a Choice and a List
Advertisements
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
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
Java list of uninstantiated classes
Java list of uninstantiated classes  Java list of uninstantiated classes
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
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
java technologies list
java technologies list  Please provide me the java technologies list
table in java
table in java  please l want to make table and insert by user
list - Java Interview Questions
list  Hi all Naturally in java a list will allow duplicates, but if i want the list which shouldn't allow duplicates then what should be the logic...) method of Interface List public boolean contains(Object o) Returns
java linked list urgent !!!
java linked list urgent !!!  Q1. Generate 10 thousand random integers with values in the range between 1 to 100. Q2. Store each randomly generated number into a node and then attach the node to a linked list. The list must
java linked list urgent !!!
java linked list urgent !!!  Q1. Generate 10 thousand random integers with values in the range between 1 to 100. Q2. Store each randomly generated number into a node and then attach the node to a linked list. The list must
java linked list urgent!!!
java linked list urgent!!!  Q1. Generate 10 thousand random integers with values in the range between 1 to 100. Q2. Store each randomly generated number into a node and then attach the node to a linked list. The list must
java linked list urgent !!!
java linked list urgent !!!  Q1. Generate 10 thousand random integers with values in the range between 1 to 100. Q2. Store each randomly generated number into a node and then attach the node to a linked list. The list must
java linked list urgent !!!
java linked list urgent !!!  Q1. Generate 10 thousand random integers with values in the range between 1 to 100. Q2. Store each randomly generated number into a node and then attach the node to a linked list. The list must
java linked list urgent !!!
java linked list urgent !!!  Q1. Generate 10 thousand random integers with values in the range between 1 to 100. Q2. Store each randomly generated number into a node and then attach the node to a linked list. The list must
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
spilt list - Java Beginners
list containing an even number of nodes, say 2k, into two circular lists each... new lists linked to by parameters sub1, and sub2 from the list initially referenced by parameter list. After ListSplit has executed, the first parameter should
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
Core java linked list example
Core java linked list example  What is the real time example for linked list
linked list in java - Java Beginners
linked list in java  Hi, how to implement linked list in java using... information. http://www.roseindia.net/java/beginners/linked-list-demo.shtml...; static List values; static { Integer vals[] = new Integer[N]; Random rn = new
java list program for common elements
java list program for common elements  hi I want program using java collections list which takes two array list elements and display common elements in both the list as an output   Please visit the following link
list of predeined methods and use java
list of predeined methods and use java  I need list of predefined methods in java like reverse,compare,tostring, etc
Order of list in java Vs Haskell.
Order of list in java Vs Haskell.  How to order of [1,2,3] to [1,2,3,2,1]in java
Link List proble, - Java Beginners
/java/beginners/linked-list-demo.shtml Hope that it will be helpful for you...Link List proble,  i have a problem about programming... this is the problem.. -create an application using Linked List this application can add
jsp list box - Java Beginners
jsp list box  I have two list boxs. the values for the first list box is retrieved from the mysql database. I want to fill the second list box...; For the above code, we have created two database tables: 1)'country' CREATE 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
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using method ? Please give me the code snipetts
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using method ? Please give me the code snipetts
Converting java arrays into list
. asList() It converts the object array into the fixed sized list Example...[]={111,222,333,444};         List list=new ArrayList();         List list1=new ArrayList();         list=Arrays.asList(ar);         list1=Arrays.asList(ar1
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
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using... ListSelectionListener { private JList list; private DefaultListModel listModel..."); //Create the list and put it in a scroll pane. list = new
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
capacity of list - Java Interview Questions
capacity of list  How to find the capacity of list. is there any method to find capacity of list like vector.capacity(); Thanks   Hi... class ListCapacity{ public static void main(String args[]){ List list = new
list files only - Java Beginners
list files only  i have to list only files and number of files in a directory? i use list() method but it returns both files and directories in parent directory.are there any specific methods that show only files? are file
List
List  getting values from a form and make a list of them and store them into database
list file number - Java Beginners
list file number  sir you still haven't understand my problem. i have to list out only the number of files in a given directory,your solution still give number of (files+directories) in given directory. are jfilechooser provide
java coding for creating table in the console
java coding for creating table in the console  write a java program to create table
creation of table using a Java swing
creation of table using a Java swing  how to create a table dynamically in Java swing
Array list in Java - arraylist type error
Array list in Java - arraylist type error  I am using Array list in Java but when i compile i get array list type error. Can anyone please explain what is array list type error and why it occurs
Array list java code - Java Beginners
Array list java code  Create an employee class with an employee id's,name & address. Store some objects of this class in an arraylist. When an employee id is given, display his name & address? Please provide the DETAIL java code
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
creating java linked list - Java Beginners
creating java linked list  how can one create a sorted linked list. thats adding it to the queue? thans in advance.  Hi , import...("Size of list: " + queue.size()); System.out.println("Queue head using peek
Array list java code - Java Interview Questions
Array list java code  Create an employee class with an employee id's... an employee id is given, display his name & address? Please provide the DETAIL java code... in your code?Please clarify it. Thanks  i need the java code
Array list java program - Java Interview Questions
Array list java program  Create an employee class with an employee... an employee id is given, display his name & address? Please provide the DETAIL java... we can display his name and address when an employee id is given? i need java
Advertisements
 

 

 

DMCA.com