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



Home Answers Viewqa Swing-AWT JTable - Cell selection

Have Programming Question? Ask it here!
 
 
 


V.Sreedevi
JTable - Cell selection
1 Answer(s)      5 years and 7 months ago
Posted in : Swing AWT



Advertisement
View Answers

September 29, 2008 at 6:26 PM


Hi friend,


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

public class JTableDemo extends JFrame {

JTable table;
DefaultTableModel tableModel;

public JTableDemo() {
table = new JTable(10, 5);
tableModel = (DefaultTableModel)table.getModel();
table.setPreferredScrollableViewportSize(table.getPreferredSize());
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

JScrollPane spane = new JScrollPane(table);
getContentPane().add(spane);

JButton button = new JButton("Click Button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
int row = table.getSelectedRow();
int column = table.getSelectedColumn();
System.out.println(row + " : " + column);
table.requestFocus();
}
});

final JButton jbutton = new JButton("De-select");
jbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (table.isEditing()) {
table.editingStopped(new ChangeEvent(jbutton));
}
tableModel.fireTableDataChanged();
table.requestFocus();
}
});

JPanel btnPanel = new JPanel(new GridLayout(2,1));
btnPanel.add(button);
btnPanel.add(jbutton);
getContentPane().add(btnPanel, BorderLayout.SOUTH);
}

public static void main(String[] args) {
JTableDemo frame = new JTableDemo();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(400,250);
frame.setVisible(true);
}
}


--------------------------------------

Read for more information.

http://www.roseindia.net/java/example/java/swing/

Thanks.

Amardeep.


Related Tutorials/Questions & Answers:
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
Advertisements
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
jtable
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
JTable - Swing AWT
JTable row selection event   Hi, it will be great if someone can share an example of row selection event in JTable
Selection based on other selection in jsp
Selection based on other selection in jsp  I am trying to create a jsp page. Where I am having a select list containing category name and for each... selection on same jsp page such that when someone select a category only the products
Displaying files on selection of date.
Displaying files on selection of date.  Hi, I am developing a GUI, where i select from and to date. On selection of from and to date the GUI should...); JButton b = new JButton("Search File"); final JTable table=new JTable
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
Help With Costructing Selection sort?
Help With Costructing Selection sort?  Using a selection sort, for each entry in the array, display the original index of the first dimension... in advance!   Please visit the following link: Java Selection Sort
interrelated two selection box
interrelated two selection box  hi i need two selection box .in 1 box all designation like manager, ceo etc , onclick on manager i should get list of managers names in second selection box.. like wise so on. from database
Selection Using JoptionPane
Selection Using JoptionPane  Help, can someone provide me the code using JOptionPane for the following:- Part A 1) Prompt user to make 3 selection... Modify the above application so that if user makes a selection that the user has
JTABLE OF JAVA
JTABLE OF JAVA  i have a jtable in java,i have used checkbox in jtable. now i want to add(submit) only those records that i have checked by checkbox how? i want small example with coding
Jtable-Java
Jtable-Java  Hi all,I have a Jtable And i need to clear the data in the table .I only Need to remove the data in the table.not the rows.Please help me
Selection Sort
(...). Like all simple sorts, selection sort is implemented with two nested loops. Simple selection sort The basic idea is to look at each...] = temp; } } } } More efficient selection sort
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
sum in JTable
sum in JTable  how to calculate sum from JTable's one field like total
JTABLE Issue
JTABLE Issue  Hi Eveyone, I am developing a small application on Swing-AWT. I have used JTABLE to show data. There is "input field" and "search... on basis of input data provided in input field. For JTABLE is on some other
checkbox selection in jsp
checkbox selection in jsp  hey guys i am working on a web based project using jsp. In my project i am having 9 check boxes in 3 rows in the same form. I want to select i check box from each row and also i want to avoid many
Image Selection - Swing AWT
Image Selection  Hi, I need to provide the image selection facility...; JButton saveButton; public DisplayImage() { super("Image Selection program... { String selection = (String)comboBox.getSelectedItem(); String
java jtable
java jtable  Hello Sir, I am developing a desktop application in which i have to display database records in jtable .now I want to read only... that in jtable. plz help me with the code
changing selection color of <button>
changing selection color of   dear all, i have loaded image in border less button tag when button is selected with tab key i get brown color rectangle around image. how do i change color of that rectangle from brown to white
selection box linked with textarea
selection box linked with textarea    function get_val(tot_val1) { document.getElementById('TextBox1').value = tot_val1; alert(tot_val1... detals i have in db with all fields .. like wise i have names in selection box sham
Selection With Ajax and JSP
Selection With Ajax and JSP  I am working at a jsp page using ajax for country , state, city selection. so if he select country it will populate the state and city selection (both). After selecting country if he select city
regarding jtable...
regarding jtable...  sir, im working with jtables. i wanted to populate a jtable from the database and when i click any row it should add a container... a container on the jtable. kindly help me sir. thanks in advance regards, rajahari
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans
How to add JTable in JPanel
How to add JTable in JPanel  How to add JTable in JPanel
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
else if (selection = * 'M'); - Java Beginners
else if (selection = * 'M');  I am trying to get 2 numbers 2... if (selection = * 'M'); ^ this is my program - what am i...; System.out.print("Enter A(dd), S(ubtract), M(ultiply):"); selection = (char
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
problem with JTable - Swing AWT
to swings.i was having an assignment like i need to create a JTable... an action event such that if i check the checkbox outside the JTable,all the checkboxes inside the JTable should be checked. details: for creating JTable
REPORT WITH JTABLE
(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane scrollPane
JTable - JDBC
JTable   Hello..... I have Jtable with four rows and columns and i have also entered some records in MsSql database. i want to increase Jtable's... { JFrame f; JPanel p; JLabel l; JTextField tf; JButton btn; JTable tb
single selection of chechbox among multiple selection when in a loop.
single selection of chechbox among multiple selection when in a loop.  i am using cmd prompt to run and execute the java pgm. here i need your help... but here am getting multiple selection(previous selected item also coming again
JTable
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract method tableChanged(TableModelEvent e) . I'll be loading values from data base when
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
enable text box and label on selection
enable text box and label on selection  hello, Please tell me how to enable label and text box on selection of drop down list box. in drop down list box all values come from database. please reply
JTable hold different components
JTable hold different components  create Jtable with two coloums,one coloumn is combobox and other normal
java swing-action on checkbox selection
( row ); } } catch(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane pane = new JScrollPane(table
JTable in java - Java Beginners
JTable in java  Sir , I have created an application with a JTable showing the records of an MS Access database table. On the same frame I have... given one , JTable table; ....... .... table.print(); Here the error
JTable - Java Beginners
JTable  can we merge two cells of one row in jtable
restrict jtable editing
restrict jtable editing  How to restrict jtable from editing or JTable disable editing?   public class MyTableModel extends...){ return false; } }   Disabling User Edits in a JTable Component
Selection Sort in Java
Selection sort in Java is used to sort the unsorted values in an array. In selection sorting algorithm, the minimum value in an array is swapped... position. This procedure is repeated till the array is sorted completely. Selection
Selection Sort In Java
Selection Sort In Java      ... are going to sort the values of an array  using selection sort.In selection sorting.... Sort the remaining  values by using same steps. Selection sort 
regarding JTable - JDBC
regarding JTable  how to populate a JTable with mysql data after clicking JButton please explain with the example
JAVA DATABASE CONNECTION WITH JTABLE
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
 

 

 

DMCA.com