java swing-action on checkbox selection

java swing-action on checkbox selection

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();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    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);
        abstractButton.setText(newLabel);
      if(newLabel.equals("Selected")){
      try {
      Class.forName("com.mysql.jdbc.Driver");
      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 (rs.next()) {
      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();
      f.add(pane);
      f.setVisible(true);
      f.pack();
      }
      }
    };
   checkBox.addActionListener(actionListener);
   checkBox.setMnemonic(KeyEvent.VK_S);
   Container contentPane = frame.getContentPane();
   contentPane.add(checkBox, BorderLayout.NORTH);
   frame.setSize(300, 100);
   frame.setVisible(true);
  }
}

Thanks









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
Advertisements
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 selection sorting algorithm, the minimum value in an array is swapped... the selection sort in Java. In selection sort algorithm, first assign minimum index
checkbox
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 
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
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
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
JSP CheckBox
;input type="checkbox" name="id" value="Java"> Java<BR> <input... 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
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
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
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
Checkbox
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
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
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
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
Maven dependency for com.vaadin - vaadin-checkbox-flow version 14.5.2 is released. Learn to use vaadin-checkbox-flow version 14.5.2 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 14.5.2 in Java projects. Follow... - vaadin-checkbox-flow version 14.5.2 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 14.5.5 is released. Learn to use vaadin-checkbox-flow version 14.5.5 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 14.5.5 in Java projects. Follow... - vaadin-checkbox-flow version 14.5.5 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 14.6.2 is released. Learn to use vaadin-checkbox-flow version 14.6.2 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 14.6.2 in Java projects. Follow... - vaadin-checkbox-flow version 14.6.2 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 18.0.5 is released. Learn to use vaadin-checkbox-flow version 18.0.5 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 18.0.5 in Java projects. Follow... - vaadin-checkbox-flow version 18.0.5 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 19.0.0 is released. Learn to use vaadin-checkbox-flow version 19.0.0 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 19.0.0 in Java projects. Follow... - vaadin-checkbox-flow version 19.0.0 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 19.0.3 is released. Learn to use vaadin-checkbox-flow version 19.0.3 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 19.0.3 in Java projects. Follow... - vaadin-checkbox-flow version 19.0.3 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 19.0.6 is released. Learn to use vaadin-checkbox-flow version 19.0.6 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 19.0.6 in Java projects. Follow... - vaadin-checkbox-flow version 19.0.6 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 19.0.9 is released. Learn to use vaadin-checkbox-flow version 19.0.9 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 19.0.9 in Java projects. Follow... - vaadin-checkbox-flow version 19.0.9 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 20.0.2 is released. Learn to use vaadin-checkbox-flow version 20.0.2 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 20.0.2 in Java projects. Follow... - vaadin-checkbox-flow version 20.0.2 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 20.0.4 is released. Learn to use vaadin-checkbox-flow version 20.0.4 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 20.0.4 in Java projects. Follow... - vaadin-checkbox-flow version 20.0.4 java library in your project. Now you...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 22.0.11 is released. Learn to use vaadin-checkbox-flow version 22.0.11 in Maven based Java projects
to use  com.vaadin - vaadin-checkbox-flow version 22.0.11 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 22.0.11 java library in your project...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox
Maven dependency for com.vaadin - vaadin-checkbox-flow version 14.8.8 is released. Learn to use vaadin-checkbox-flow version 14.8.8 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 14.8.8 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 14.8.8 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 22.0.14 is released. Learn to use vaadin-checkbox-flow version 22.0.14 in Maven based Java projects
to use  com.vaadin - vaadin-checkbox-flow version 22.0.14 in Java projects. Follow... and includes  com.vaadin - vaadin-checkbox-flow version 22.0.14 java library...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox
Maven dependency for com.vaadin - vaadin-checkbox-flow version 23.0.7 is released. Learn to use vaadin-checkbox-flow version 23.0.7 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 23.0.7 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 23.0.7 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 23.0.4 is released. Learn to use vaadin-checkbox-flow version 23.0.4 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 23.0.4 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 23.0.4 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 23.3.0 is released. Learn to use vaadin-checkbox-flow version 23.3.0 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 23.3.0 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 23.3.0 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 22.0.25 is released. Learn to use vaadin-checkbox-flow version 22.0.25 in Maven based Java projects
to use  com.vaadin - vaadin-checkbox-flow version 22.0.25 in Java projects. Follow... and includes  com.vaadin - vaadin-checkbox-flow version 22.0.25 java library...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox
Maven dependency for com.vaadin - vaadin-checkbox-flow version 22.0.25 is released. Learn to use vaadin-checkbox-flow version 22.0.25 in Maven based Java projects
to use  com.vaadin - vaadin-checkbox-flow version 22.0.25 in Java projects. Follow... and includes  com.vaadin - vaadin-checkbox-flow version 22.0.25 java library...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox
Maven dependency for com.vaadin - vaadin-checkbox-flow version 14.9.3 is released. Learn to use vaadin-checkbox-flow version 14.9.3 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 14.9.3 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 14.9.3 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 23.1.15 is released. Learn to use vaadin-checkbox-flow version 23.1.15 in Maven based Java projects
to use  com.vaadin - vaadin-checkbox-flow version 23.1.15 in Java projects. Follow... and includes  com.vaadin - vaadin-checkbox-flow version 23.1.15 java library...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox
Maven dependency for com.vaadin - vaadin-checkbox-flow version 23.1.14 is released. Learn to use vaadin-checkbox-flow version 23.1.14 in Maven based Java projects
to use  com.vaadin - vaadin-checkbox-flow version 23.1.14 in Java projects. Follow... and includes  com.vaadin - vaadin-checkbox-flow version 23.1.14 java library...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox
Maven dependency for com.vaadin - vaadin-checkbox-flow version 23.2.7 is released. Learn to use vaadin-checkbox-flow version 23.2.7 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 23.2.7 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 23.2.7 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 23.0.2 is released. Learn to use vaadin-checkbox-flow version 23.0.2 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 23.0.2 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 23.0.2 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 22.0.10 is released. Learn to use vaadin-checkbox-flow version 22.0.10 in Maven based Java projects
to use  com.vaadin - vaadin-checkbox-flow version 22.0.10 in Java projects. Follow... and includes  com.vaadin - vaadin-checkbox-flow version 22.0.10 java library...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox
Maven dependency for com.vaadin - vaadin-checkbox-flow version 14.8.6 is released. Learn to use vaadin-checkbox-flow version 14.8.6 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 14.8.6 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 14.8.6 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 22.0.7 is released. Learn to use vaadin-checkbox-flow version 22.0.7 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 22.0.7 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 22.0.7 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow
Maven dependency for com.vaadin - vaadin-checkbox-flow version 22.0.3 is released. Learn to use vaadin-checkbox-flow version 22.0.3 in Maven based Java projects
; com.vaadin - vaadin-checkbox-flow version 22.0.3 in Java projects. Follow...; com.vaadin - vaadin-checkbox-flow version 22.0.3 java library in your...-checkbox-flow released The developers of   com.vaadin - vaadin-checkbox-flow

Ads