JTable - Cell selection

JTable - Cell selection

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 - Swing AWT
JTable row selection event   Hi, it will be great if someone can share an example of row selection event in JTable
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
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
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
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
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
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
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
ModuleNotFoundError: No module named 'selection'
ModuleNotFoundError: No module named 'selection'  Hi, My Python... 'selection' How to remove the ModuleNotFoundError: No module named 'selection' error? Thanks   Hi, In your python environment you
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
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
How to add JTable in JPanel
How to add JTable in JPanel  How to add JTable in JPanel
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
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
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
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
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
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
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 hold different components
JTable hold different components  create Jtable with two coloums,one coloumn is combobox and other normal
JTable Pagination
JTable Pagination  Hello , I have the following Code. I am able to fetch the Data from the Database. But i need to implement pagination for the same. Can someone please help me out with this ? I have tried out many things from
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
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
JTable - Java Beginners
JTable  can we merge two cells of one row in jtable
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
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
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'causal-selection'  Hi, My... named 'causal-selection' How to remove the ModuleNotFoundError: No module named 'causal-selection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'model-selection'
ModuleNotFoundError: No module named 'model-selection'  Hi, My... named 'model-selection' How to remove the ModuleNotFoundError: No module named 'model-selection' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'model-selection'
ModuleNotFoundError: No module named 'model-selection'  Hi, My... named 'model-selection' How to remove the ModuleNotFoundError: No module named 'model-selection' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'blacken-selection'
ModuleNotFoundError: No module named 'blacken-selection'  Hi, My... named 'blacken-selection' How to remove the ModuleNotFoundError: No module named 'blacken-selection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'causal-selection'  Hi, My... named 'causal-selection' How to remove the ModuleNotFoundError: No module named 'causal-selection' error? Thanks   Hi, In your
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
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
regarding JTable - JDBC
regarding JTable  how to populate a JTable with mysql data after clicking JButton please explain with the example

Ads