java swing-action on checkbox selection



Share on Google+Share on Google+

java swing-action on checkbox selection
1 Answer(s)      6 years and 9 months ago
Posted in : Java Beginners

I am working in netbeans and mysql.On selecting a check box, the data from database must be retrieved. i need the action preformance of check box...could nybody?....if could...!thanks

View Answers

January 18, 2011 at 12:56 PM

Hi Friend,

Try the following code:

import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;

public class CheckBoxAction {

  private static String des = "Deselected";
  private static String sel = "Selected";
  public static void main(String args[]) {
    JFrame frame = new JFrame();
    JCheckBox checkBox = new JCheckBox(des);

    ActionListener actionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        Vector columnNames = new Vector();
        Vector data = new Vector();
        AbstractButton abstractButton = (AbstractButton)actionEvent.getSource();
        boolean selected = abstractButton.getModel().isSelected();
        String newLabel = (selected ? sel : des);
      try {
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
      Statement st = con.createStatement();
      ResultSet rs= st.executeQuery("Select * from employee");
      ResultSetMetaData md = rs.getMetaData();
      int columns = md.getColumnCount();
      for (int i = 1; i <= columns; i++) {
      columnNames.addElement( md.getColumnName(i) );
      while ( {
      Vector row = new Vector(columns);
      for (int i = 1; i <= columns; i++) {
      row.addElement( rs.getObject(i) );
      data.addElement( row );
      catch(Exception e){}
      JTable table = new JTable(data, columnNames);
      JScrollPane pane = new JScrollPane(table);
      JFrame f=new JFrame();
   Container contentPane = frame.getContentPane();
   contentPane.add(checkBox, BorderLayout.NORTH);
   frame.setSize(300, 100);



Related Tutorials/Questions & Answers:
java swing-action on checkbox selection
java swing-action on checkbox selection  I am working in netbeans... need the action preformance of check box...could nybody?....if could...!thanks...(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox checkBox = new JCheckBox(des
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
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
Java code for enabling filter to a checkbox and disabling filter to that checkbox after uncheked
Java code for enabling filter to a checkbox and disabling filter to that checkbox after uncheked  Can anybody say the Java code for enabling filter to a checkbox and disabling filter to that checkbox after uncheked
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
Selection Sort in Java
Selection sort in Java is used to sort the unsorted values in an array... in Java. In selection sort algorithm, first assign minimum index in key as index... the whole list is sorted. Example of Selection Sort in Java: public class
checkbox  how to insert multiple values in database by using checkbox in jsp
insert checkbox in cell using POI api in java
insert checkbox in cell using POI api in java  I need to insert checkbox in excel cell using POI and java. Any one help me on this. Ashok S
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 
java code using combobox,radiobutton,checkbox
java code using combobox,radiobutton,checkbox  hi, send me java code for entering student details into ms access database, the code should includes combo box,radiobutton and checkboxes pl send as early as possible
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 that when in a loop i trying to choose single checkbox among multiple checkboxes
Selection based on other selection in jsp
Selection based on other selection in jsp  I am trying to create... category there are products which are taken from a ms access table using a java... selection on same jsp page such that when someone select a category only the products
Checkbox method
Checkbox method  what is the method to check if the checkbox is checked
how to add components (like button , checkbox etc) in a table column in core java
how to add components (like button , checkbox etc) in a table column in core java  plz tell me how to add components(like button, checkbox, radiobutton etc)in a table column in core java
JSP CheckBox
="checkbox" name="id" value="Java"> Java<BR> <input type="checkbox... JSP CheckBox          JSP CheckBox is used to create a CheckBox in JSP
JSP Checkbox
JSP Checkbox In this tutorial you will learn how to create a checkbox using JSP. As we know, checkbox allows multiple selection at a time, but radio... selection always go for checkbox. Using the example we will try to understand how
UIButton checkbox
UIButton checkbox  iPhone UIButton checkbox example required.. can any one please explain me.. how to create a checkbox button using UIButton in XIB
Help With Costructing Selection sort?
in advance!   Please visit the following link: Java 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
Checkbox       A checkbox is again a label which is displayed as a pushbutton as shown in the example... of the checkbox is either true or false. However, the initial state is false
How to create CheckBox On frame
How to create CheckBox On frame       This is very simple java program. In this section, you will learn how to create CheckBox on the frame. In the Java AWT, top-level windows
Ajax Checkbox
Ajax Checkbox  I want ajax code for checkboxes.The scenario is that if a selectbox is selected the corresponding values to it in the database table are to be checked in the checkbox.....Please do help me
How to check a checkbox - Struts
How to check a checkbox  Hello Community, How can i check a checkbox... please help me with the syntax??  Hi friend, my checkbox example Java JDBC Hibernate JSP Servlets Struts
enable disable checkbox in javascript
enable disable checkbox in javascript  How to enable disable checkbox in javascript
refresh checkbox jframe
refresh checkbox jframe  How to refresh checkbox button in JFrame
Reset checkbox style to default
Reset checkbox style to default  Reset checkbox style to default   input[type="checkbox"] { /* styles
Maintain checked checkbox status
ultimate aim is to avoid "duplicate " selection of checkbox records . i am stuck...Maintain checked checkbox status  Hi everyone In my JSP application, i have database table stored in mysql. when i display there recors using
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
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
Displaying files on selection of date.
for same.   Here is a java swing code that accepts two dates and search...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
highlight uitableviewcell on selection
the UITableViewCell on selection in my application.   UITableViewCell... highlight it or use the default selection for the cell in UITableView. Also you can disable the the stye by setting StyleNone to cell selection. But in case
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