Share on Google+Share on Google+

raveen
instead of text boxe i have to show check box as selected.
1 Answer(s)      4 years and 11 months ago
Posted in : Swing AWT

i have one text field. in that iam getting boolean value either true or false from the database. when ever the valsue is there in textfield, instead of text boxe i have to show check box as selected.

Thanks In advance R.Raveen.

Ads

View Answers

May 17, 2012 at 3:46 PM


The given code retrieves the data from the database table and show values on Frame.

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

class ShowCheckboxSelected extends JFrame
{

ShowCheckboxSelected(){
String des = "Deselected";
String sel = "Selected";

JLabel label1 = new JLabel();
label1.setText("Name:");
JTextField text1 = new JTextField(20);

JLabel label2 = new JLabel();
label2.setText("Age:");
JTextField text2 = new JTextField(20);

JLabel label3 = new JLabel("Indian?");
JCheckBox check = new JCheckBox();


JPanel panel=new JPanel(new GridLayout(3,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(check);
add(panel);

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from employee where id='2'");
        String str=" ";
        if(rs.next()){
            text1.setText(rs.getString("name"));
            text2.setText(Integer.toString(rs.getInt("Age")));
            str=rs.getString("nationality");
            System.out.println(str);
            if(str.equals("true")){
                check.setSelected(true);
            }
            else{
                check.setSelected(false);
            }

        }
    }
catch(Exception e){}

}
public static void main(String arg[]){
try
{
ShowCheckboxSelected frame=new ShowCheckboxSelected();
frame.pack();
frame.setVisible(true);
}
catch(Exception e)
{}
}
}









Related Tutorials/Questions & Answers:
instead of text boxe i have to show check box as selected.
instead of text boxe i have to show check box as selected.  i have... the database. when ever the valsue is there in textfield, instead of text boxe i have to show check box as selected. Thanks In advance R.Raveen.
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
Dynamically display values in dropdown box and then show the selected values... this code it is adding one more value to the dropdown box and showing as selected. so if I have 5 values in the dropdown this selected one is added as 6th values
Advertisements
approve or reject multiple selected rows using check box
approve or reject multiple selected rows using check box   Select Article Document Type Document Sub Type
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
in the list box. Somehow I can just show only one as selected but not multiple records...Dynamically display values in dropdown box and then show the selected values..., This is for Updating. I had two SQL queries one for only selected values
check box in jsp
check box in jsp  hey guys i am working on a web based project using jsp. In my project 1 am having 9 check boxes in 3 rows in the same form. I want to select 1 check box from each row and also i want to avoid many check box
how can i store text box values as it is in database table
how can i store text box values as it is in database table  CUSTOMER DESCRIPTION
click on check box
click on check box  I create a check box in HTML and when i click on my check box relative information in page store in database
textfield selected text
textfield selected text  How to select text in text field
Show text field & check input using jQuery
Show text field & check input using jQuery In this tutorial, we will discuss about how to display 'text field' by a button click & check... how to display 'text field' by a button click & check input using
i want to select a multiple value of check box by using onclick or onchange event without using from submission
i want to select a multiple value of check box by using onclick or onchange event without using from submission   i have 4 check box name 1)profile... the result is ok but after getting value of first box now i want a result of second box
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below... code for me jsp file... <[email protected] contentType="text/html" pageEncoding...;<input type="text" value =" " property= "amount" id='pricecheck'/> <
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below... code for me jsp file... <[email protected] contentType="text/html" pageEncoding...;<input type="text" value =" " property= "amount" id='pricecheck'/>
Dynamic check box problem
Dynamic check box problem  In my project i have used a dynamic table, in the each row of that table there is one check box [that i have created...='enable_text()' name="check"> <td><input type="text" name="name
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
two text box problem
two text box problem  i have two text box in two different pages and same variable use in two text box when enter value in first text box it's reflection show in second text box , how i reduce it in jsf ?   Hi Friend
check box left justification
check box left justification  how to make a check box left justification which is at right end? thanks in advance
how to insert check box
how to insert check box   how to insert check box into jtable row in swing
I am getting Undefined in Text Box Very Urgent - JSP-Servlet
I am getting Undefined in Text Box Very Urgent  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your superb reply. I got the coding. But I find... the value "Undefined" in Emp ID text box which is present in the main page.. Here's
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
HI Jsp check box..!
HI Jsp check box..!  Hi all.. I want to update the multiple values of database table using checkbox..after clicking submit the edited field has to update and rest has to enable to update...please help me..its urgent
show selected date range in calender
show selected date range in calender  helo, i'm working in a project in jsp. suppose thier are 2 textbox 1.start date 2. end date whatever date selected in these textbox get highlighted in the calendar, please help
check box condition
check box condition  Hai, my application has two check box one for chart and another one for table.when We click chart check box download only chart but table also download.same problem in table slection..xsl coding was used
I have a tex box. in that i want user should enter data in the format specified(for eg--a_b_c_d_e_)how to write code for it.
I have a tex box. in that i want user should enter data in the format specified(for eg--a_b_c_d_e_)how to write code for it.  I have a tex box. in that i want user should enter data in the format specified(for eg--abcde_)how
Text box Checking
Text box Checking  I want to Write only the word A-Z in a text box What is the code
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface... is your code, we have modified it. import java.io.*; interface arith { int a=5
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface... is your code, we have modified it. import java.io.*; interface arith { int a=5
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
Check Box Validation in PHP - PHP
Check Box Validation in PHP  How can validations done on check boxes more than 3?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/javascript-array/javascript-array-checkboxes.shtml
Tutorials   
Java Spring Hibernate Struts Training Change JPanel background color from mouse entered/exit event JTable Pagination Jcombobox JAVA SWING how can i display a pdf file in a jtextarea Crop Image Code in Applet Crop Image Code in Applet Image Manipulation in Swing AWT Applet Ho to get virtual key code. how to show set of images continously using JScrollpane in java how to show set of images continously using JScrollpane in java How to connect on screen keyboard to system. How to connect on screen keyboard to system. query java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings Download. how to open one Jframe from main method call Urgent requirement display shapes i am getting an error in adding a menu item to a menu. I am trying to develop a Image Sliding application but unfortunately its not working... Can any one help me in this Sliding window protocol how to update the value of jslider how to update the value of jslider how to update the value of jslider how to update the value of jslider how to update the value of jslider Jbutton in JTable cells program code java textfield problem swing retrieve data from database in java swing form using prev n next buttons retrieve data from database in java swing form using prev n next buttons How to close a frame on action event of a button from a different class ? searching the data swings for webnms Jpanel allignment pass data from java frame to file code for traffic control system simulation Bank Management System how to maKE Jcombox editable after saveing value init. i havei) aJTextField and one button. when place the cursor or enter anything in the test field then only button should be enabled.by default the button should be disabled. i havei) a jtable with few cloumns and few rows andii) one button. when place the cursor in any of the table's column cell. i need to enable the button.by default the button should be disabled. PDF Comparator i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox. issue on jcombobox

Ads

 
Advertisement null

Ads