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



Home Answers Viewqa Swing-AWT JTable - Cell selection
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


V.Sreedevi
JTable - Cell selection
1 Answer(s)      6 years 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
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
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
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
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
sum in JTable
sum in JTable  how to calculate sum from JTable's one field like total
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
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
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
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
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
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
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 duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
Advertisements
 

 

 

DMCA.com