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



Home Answers Viewqa Java-Beginners java swing-action on checkbox selection

Have Programming Question? Ask it here!
 
 
 


ranjani
java swing-action on checkbox selection
1 Answer(s)      3 years and 7 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


Advertisement
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 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
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
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
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 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
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
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
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
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
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
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
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 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
Checkbox Tag <html:checkbox>:
:checkbox > tag. Example code : Creating an Action Class...Checkbox Tag <html:checkbox>:       html: checkbox Tag -  is used to create a  Checkbox Input
Checkbox pagination problem
Checkbox pagination problem  HI ., Following is my code test.jsp... Selected Domains " type=checkbox value="${domain.domainName}">... checkbox of table"Table Containts" and submit ">>" button, then in "Total
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
PHP Dynamic CheckBox
PHP Dynamic CheckBox  Help with Dynamic Checkbox in PHP
Addin checkbox to table
Addin checkbox to table  how to add checkboxes in JTable
Displaying the entire row in another datatable when the checkbox is checked - Java Server Faces Questions
Displaying the entire row in another datatable when the checkbox is checked  Dear Sir, I have a jsf datatable which has 8 columns. I need to fetch a row completely when the check box corresponding to that row is checked
checkbox value in php
checkbox value in php  In my HTML,PHP form ..we have a check box that is working fine. But anyhow i am not able to get the value of it. Can anyone suggest how to get the value of checkbox in PHP
multiple language selection
multiple language selection  Hi how can i do a java program using swing that changes the language like malayalam/tamil etc with languages on a drop down menu
Dojo Tree With Checkbox - Framework
structure in a jsp along with checkbox besides each node. The tree structure... with tree structure. The checkbox will have 3 states: (1) partially checked, (2) checked, and (3) unchecked. It would work the way a feature-selection widget does
Problem with DOJO tree with checkbox - Framework
to generate a tree structure in a jsp along with checkbox besides each node. The tree... opens with tree structure. The checkbox will have 3 states: (1) partially checked, (2) checked, and (3) unchecked. It would work the way a feature-selection
Adding checkbox to List as item
Adding checkbox to List as item   can we add checkox to List   Hi Friend, Try the following code: import java.awt.*; import javax.swing....()); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION
Checkbox blocked - WebSevices
Checkbox blocked  Hi, i design online ticket reservation for bus. It contains no of seats. if i choose 3 or 4 seats checkbox,it will stored in my database. After i refreshing the page that checkbox seats are blocked
Help to maintain state of checkbox
the state of checkboxes across pages. What happens is when i check one checkbox and then go to say 2nd page then check one checkbox there and when i return to previous page the checked box is again unchecked. Means the status of the checkbox
Dojo Checkbox
some action on press.  Try Online: Checkbox [Checkboxes are used when...Dojo Checkbox          In this section, you will learn how to create a checkbox in dojo
Adding checkbox in table using that delete table rows
the selected rows using swing in java...Adding checkbox in table using that delete table rows  I need coding for how to add checkbox in table,the table data from database.Using
how to get the checkbox value in jsp
how to get the checkbox value in jsp  how to get the checkbox value in jsp?   JSP CheckBox Example - how to get the checkbox value in jsp
JTable - Cell selection - Swing AWT
information. http://www.roseindia.net/java/example/java/swing/ Thanks. Amardeep...(ListSelectionModel.SINGLE_SELECTION); JScrollPane spane = new JScrollPane(table
 

 

 

DMCA.com