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



Home Answers Viewqa Java-Beginners Java table & list
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Amol T Kokane
Java table & list
3 Answer(s)      3 years and 8 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
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
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
Core java linked list example
Core java linked list example  What is the real time example for linked list
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
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
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
Advertisements
 

 

 

DMCA.com