Jcheckbox problem...

hi all ..
i wrote an application in swing to generate a Html form dynamically and save to a folder,but in my application,i could only generate and save only one name from the listbox
Now all that is i need a checkbox besides each formname in the listbox and when i check the names and click generate button,multiple forms should be generated and saved....can any one please throw their knowledge on this and solve for me...
Thanks in advance
*********** here is my applicaiton
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.lang.*;
import java.sql.*;
public class MyAppFrame extends JFrame implements ActionListener{
     //-- class members
     JTextField jtf_Text;
     JButton jb_Button,G_Button;
     JList j1_List;
     JCheckBox Jb;
     Vector v;
private JScrollPane jpane;
Connection con;
Statement st,st1;
ResultSet rs,rs1;
final JFileChooser fc = new JFileChooser();
String temp = "";
String FormCode;
String SectionCode;
String SQL_sectionCode;
int i;
MyAppFrame(String title) {
     super(title);
     setSize(600,500);
     Container contentPane = getContentPane();
     contentPane.setLayout(new BorderLayout());
          JPanel panel = new JPanel();
     panel.setLayout(new FlowLayout());
          panel.add(new JLabel("Target Folder: "));
panel.add(jtf_Text = new JTextField(10));
jb_Button=new JButton("List");
jb_Button.addActionListener(this);
panel.add(jb_Button);
G_Button=new JButton("Generate");
panel.add(G_Button);
G_Button.addActionListener(this);
contentPane.add(panel,BorderLayout.NORTH);
panel = new JPanel();
          panel.setLayout(new GridLayout(2,1));
          panel.add(new JLabel("Selected Forms:"));
v=new Vector();
panel.add(j1_List = new JList());
//j1_List.setCellRenderer(new CheckListRenderer());
j1_List.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
j1_List.setBorder(new EmptyBorder(0,4,0,0));
// j1_List.addMouseListener(new MouseAdapter();
jpane = new JScrollPane();
jpane.getViewport().add(j1_List);
contentPane.add(panel, BorderLayout.CENTER);
panel.add(jpane);
          addWindowListener(new ExitListener());
     setVisible(true);
     public static void main(String[] args) {
     MyAppFrame maf = new MyAppFrame("Form Selection");
class ExitListener extends WindowAdapter{
public void windowClosing(WindowEvent event) {
System.exit(0);
private void con(JList ref){
     try{
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con = DriverManager.getConnection("jdbc:odbc:satya");
     System.out.println("Set Connection");
     st=con.createStatement();
     st1=con.createStatement();
     String query="select form_name from form";
     System.out.println(query);
rs=st.executeQuery(query);
while(rs.next()){
          String name = rs.getString("form_name");
          v.add(name);
               j1_List.setListData(v);
               rs.close();
               catch(Exception e)
e.printStackTrace();
public void actionPerformed(ActionEvent e) {
String flag = e.getActionCommand();
if(flag.equals("List")){
this.con(j1_List);
jb_Button.setEnabled(false);
else
     try{
rs=st.executeQuery("select title,form_code from form where form_name='"+(String)j1_List.getSelectedValue()+"'");
     while(rs.next()){
     temp=rs.getString(1);
     FormCode=rs.getString(2);
rs.close();
}catch(Exception e3){System.out.println("here"+e3);}
     //rs=st.executeQuery("SELECT form_section_rel.form_code, section.section_title, form_section_rel.section_code, form_section_rel.order_id FROM section INNER JOIN form_section_rel ON section.section_code = form_section_rel.section_code where form_code = '" + FormCode + "'ORDER BY form_section_rel.form_code, form_section_rel.order_id");
     //rs1=st1.executeQuery("
     StringBuffer sb = new StringBuffer();
     sb.append("<html>");
     sb.append("<style>");
     sb.append("td{");
     sb.append("font-family : Arial,Helvetica,Sans-serif");
     sb.append("font-size : 12px");
     sb.append("color : #000000");
     sb.append("}");
     sb.append("</style>");
     sb.append("<HEAD><META HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\">");
     sb.append("<META HTTP-EQUIV=\"EXPIRES\" CONTENT=\"0\">");
     sb.append("<TITLE>Service Window Document </TITLE>");
     sb.append("<link rel=\"stylesheet\" href=\"main.css\">");
     sb.append("</HEAD><body bgcolor=\"#ffffff\" bgproperties=\"fixed\" text=\"#000000\" leftmargin=\"0\" topmargin=\"0\" margin width=\"0\" margin height=\"0\">");
sb.append("<TABLE width=\"100%\" border=\"0\" cell spacing=\"0\" cell padding=\"0\">");
     sb.append("<TR>");
     sb.append("<TD bgcolor=\"#ffffff\" align=\"top\">");
     sb.append("<TABLE align=\"left\" width=\"100%\">");
     sb.append("<TR align=\"top\">");
     sb.append("<the><font color=\"#ff0000\"></font></th>");
     sb.append("</TR>");
     sb.append("<TR align=\"top\">");
     sb.append("<TD row span=\"2\">");
     sb.append("<form name=\"sw_form\" method= post action=\"post\">");
     sb.append("<table border=0 cell spacing=\"0\" cell padding=\"0\" border color=\"#000000\" width=\"450\">");
     sb.append("<tr><td>");
     sb.append("<table border=0 cell spacing=\"0\" cell padding=\"0\" border color=\"#000000\" width=\"450\">");
     sb.append("<div align=\"center\">");
     sb.append("<tr>");
     sb.append("<td colspan=\"2\">");
     sb.append("<table border=\"1\" border color=\"#ffffff\" width=\"450\" cell spacing =\"0\" cell padding=\"3\">");
     sb.append("<tr>");
     sb.append("<th align=\"center\" bgcolor=\"#990000\"><font color=\"#ffcc00\"><b>"+temp+"</b></font></th>");
sb.append("</tr>");
     sb.append("</table>");
     sb.append("</td>");
     sb.append("</tr>");
     sb.append("</table>");
     sb.append("</td></tr>");
try{
rs=st.executeQuery("SELECT form_section_rel.form_code, section.section_title, form_section_rel.section_code, form_section_rel.order_id FROM section INNER JOIN form_section_rel ON section.section_code = form_section_rel.section_code where form_code = '" + FormCode + "'ORDER BY form_section_rel.form_code, form_section_rel.order_id");
rs.next();
do{
     sb.append("<table width=\"\">");
     sb.append("<tr><td bordercolor=\"#FFFFCC\"> </td></tr>");
     sb.append("<tr><td colspan=2 width=450>");
     sb.append("<fieldset><legend>");
     sb.append(rs.getString("section_title"));
     SectionCode = rs.getString("section_code");
     System.out.println(SectionCode);
     i=Integer.parseInt(SectionCode);
     sb.append("</legend>");
     sb.append("<table width=\"\">");
     sb.append("<tr><td bordercolor=\"#FFFFCC\">  </td></tr>");
     SQL_sectionCode ="SELECT SectionUI_Rel.SectionCode, SectionUI_Rel.OrderID, ui_components.* FROM ui_components INNER JOIN SectionUI_Rel ON ui_components.pid = SectionUI_Rel.ComponentID WHERE (((SectionUI_Rel.SectionCode)='"+SectionCode+"'))";
     rs1 =st1.executeQuery(SQL_sectionCode);
     while(rs1.next())
     String type=rs1.getString("ui_type");
     String val=rs1.getString("validationtype");
     int len=val.length();
     val=val.substring(3,len);
     String man=rs1.getString("mandatory");
     if(type.equals("textbox") && man.equals("1")){
     sb.append("<TR><TD>"+rs1.getString("labelname")+":</TD><TD><input type="+type+" name="+rs1.getString("fieldname")+" maxlength ="+val +"> <font color=\"#ff0000\">*</font></TD></TR>");
     else if(man.equals("0")) {
sb.append("<TR><TD>"+rs1.getString("labelname")+":</TD><TD><input type="+type+" name="+rs1.getString("fieldname")+" maxlength ="+val +"></TD></TR>");
else if(type.equals("dropdown")){
     sb.append("<TR><TD>"+rs1.getString("labelname")+":</TD><TD><select name="+type+" name="+rs1.getString("fieldname")+" </select></TD></TR>");
     else if(type.equals("static")){
     sb.append("<TR><TD>"+rs1.getString("labelname")+":</TD></TR>");
else if(type.equals("textarea")){
     sb.append("<TR><TD>"+rs1.getString("labelname")+":</TD><TD><textarea name="+rs1.getString("fieldname")+"></textarea></TD></TR>");
else if(type.equals("radio")){
     sb.append("<TR><TD>"+rs1.getString("labelname")+":</TD><TD><input type="+type+" name="+rs1.getString("fieldname")+"></TD></TR>");
else if(type.equals("checkbox")){
     sb.append("<TR><TD>"+rs1.getString("labelname")+":</TD><TD><input type="+type+" name="+rs1.getString("fieldname")+"></TD></TR>");
     sb.append("</table>");
     sb.append("</fieldset>");
     sb.append("</td></tr>");
     sb.append("</table>");
     } while( rs.next());
//sb.append("</form></body></html>");
}catch(Exception e4){
System.out.println(e4);
sb.append("</form></body></html>");
     String formname=(String)j1_List.getSelectedValue();
     String Dir=jtf_Text.getText();
     Dir +="/"+formname+".html";
     if(formname!=null && Dir !=null)
     try
     PrintWriter out= new PrintWriter(new FileWriter(Dir));
BufferedWriter br=new BufferedWriter(out);
     out.println(sb +"\n");
     out.close();
catch(Exception e1)
System.out.println(e1);
//jb_Button.setEnabled(false);

Huh?
1) If you want to use a method, you shouldn't override it
2) I don't see any reason to extend JCheckBox at all
3) What do you want your method to do that isSelected() doesn't already do?
4) if (box.isSelected()) suffices - no reason to compare true or false with true.
5) in this case "return box.isSelected()" suffices for the entire method.
I totally don't understand your problem. Updating the table can be done with or without a SwingWorker in the button's ActionListener.

Similar Messages

  • AlphaComposite and JCheckBox problem

    Hello,
    my problems looks as follows:
    1. i got JPanel pX with displayed picture on it
    2. there's translucent JPanel pY (with alpha = 12%) on pX
    3. there're several components (JTextFileds, JButtons, JCheckBoxes) on pY
    All I want is that pY should be translucent (it is) and all of its components sholdn't be. It works great until I click on any of JCheckBoxes. It repaints very strange, on its background appear random fragments of pX, pY etc until it become totally opaque.
    Hiding and showing pY "repairs" it.
    My pYClass is defined as follows:
    class pyClass extends JPanel
      public pYClass(float _alpha)
        this.putClientProperty("alpha", AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
      public void painComponent(Graphics g)
        Graphics2D g2 = (Graphics2D) g;
        Composite oldc = g2.getComposite();
        AlphaComposite alc = (AlphaComposite) this.getClientProperty("alpha");
        if (alpha != null) g2.setComposite(alc);
        super.paintComponent(g);
        if (alpha != null) g2.setComposite(oldc);
    }Any help would be great
    Regards
    Marcin Zochowski
    sorry for my english

    Hi, it's me again.
    I got through java spurce codes and i think i got it. Problem is in doClick method in AbstractButton. It calls paintImmediately() methow which clears rectangle region "under" icon and text.
    So my question is:
    how to override AbstractButton.doClick() method in class that extends JCheckBox?
    I wrote in MyCheckBox class my own public void doClick(){return;} but it seems that it isn't called at all :-(
    Regards
    Marcin Zochowski

  • JTable with JCheckbox problems

    Ok so I have a couple of questions. I have a JTable with a column represented as a checkbox.
    1. If I put the checkbox column as the first in the table, the rest of the cells are blank/null. Any idea what the reason is?
    2. What is the best workaround to having draggable columns, meaning icons/checkboxes don't render if you move the columns around?
    3. Does anyone have some links to good resources on JTables and things like custom components in them. I have googled but don't get many good links so would appreciate any help
    Code snippet as follows:
    public class ClobberTableCellRenderer implements TableCellRenderer
    private JPanel renderPanel = new JPanel(new BorderLayout());
    private JLabel renderLbl = new JLabel("");
    private JCheckBox checked = new JCheckBox();
    private Icon successIcon;
    private Icon errorIcon;
    public Component getTableCellRendererComponent(JTable table,
    Object value,
    boolean isSelected,
    boolean hasFocus,
    int row,
    int column)
    String columnName = table.getModel().getColumnName(column);
    if (value == null)
    return null;
    else if ("Status".equals(columnName) && "ok".equals(value))
    renderLbl.setIcon(successIcon);
    renderLbl.setText("");
    renderPanel.remove(checked);
    else if ("Status".equals(columnName) && "error".equals(value))
    renderLbl.setIcon(errorIcon);
    renderLbl.setText("");
    renderPanel.remove(checked);
    else if ("Active".equals(columnName))
    renderLbl.setText("");
    renderPanel.add(checked);
    renderPanel.setBackground(Color.white);
    else
    renderLbl.setHorizontalAlignment(value instanceof Date || value instanceof Number ? JLabel.RIGHT : JLabel.LEFT);
    renderLbl.setIcon(null);
    renderLbl.setText(value instanceof Date ? df.format((Date)value) : value.toString());
    renderLbl.setToolTipText(null);
    renderPanel.setToolTipText(null);
    renderPanel.remove(checked);
    if (isSelected)
    renderPanel.setBackground((Color)UIManager.getDefaults().get("Table.selectionBackground"));
    else
    renderPanel.setBackground((Color)UIManager.getDefaults().get("Table.background"));
    return renderPanel;
    }

    Hi :) I have also worked on JTables and JCheckBoxes before. This article
    helped me a lot: http://www-128.ibm.com/developerworks/java/library/j-jtable/

  • Problem with JCheckBox in a JTable

    Hello,
    I have a JTable with JCheckBox as Editor for boolean values.
    I added a ListSelectionListener on that JTable.
    My problem is :
    when I click on a cell which have a JCheckBoxEditor, there is only one event generated : the one which unselect the row previously selected.
    So i can't answer the selection.
    what could have append ?
    thanks a lot.
    fleur.

    hi,
    I have no custom editor for this table.
    here is my code :
    public VDEComposant(Locale langue,InterfaceModeleur listener,Composant composant,int largeur) {
    super(langue,listener,largeur);
    this.setLayout(new BorderLayout());
    _modele=listener.getModele();
    _composantCourant=composant;
    this.addComposantsListener((ComposantsListener)listener.getGestionnaire());
    construitBarreOutils();
    setNbLigne1(this.listeComposant(composant).size());
    int m=0;
    if (composant==Composant.COMPOSANT){
    _donCompPereApTM=this.creeModeleDonnee1(composant);
    _donCompPereApTM.addTableModelListener(this);
    setTableau1(new JTable(_donCompPereApTM));
    m=1;
    else{
    if (composant.getPere()==Composant.COMPOSANT){
    _donCompApTM=creeModeleDonnee1(composant);
    _donCompApTM.addTableModelListener(this);
    setTableau1(new JTable(_donCompApTM));
    else {
    _donCompUtTM=creeModeleDonnee1(composant);
    _donCompUtTM.addTableModelListener(this);
    setTableau1(new JTable(_donCompUtTM));
    getTableau1().addMouseListener(((OngletDonnees)((OngletDonnees)getIHM().getOngletDonnees())).getOngletComposants());
    MultipleComboBoxCellEditor editor = new MultipleComboBoxCellEditor(new JComboBox());
    getTableau1().getColumnModel().getColumn(4+m).setCellEditor(editor) ;
    getTableau1().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    getTableau1().getSelectionModel().addListSelectionListener(this);
    Dimension d1 = new Dimension(_largeur, getNbLigne1()*16);
    JScrollPane sc1 = new JScrollPane(getTableau1());
    sc1.setViewportView(getTableau1());
    if((composant.getPere()!=null)&&(composant.getPere()!=Composant.COMPOSANT)){
    this.add(_outils,BorderLayout.NORTH);
    String s="";
    if((composant.getPere()==null)||(composant.getPere()==Composant.COMPOSANT)){
    String sc="";
    if(composant==Composant.COMPOSANT_IMAGE){
    sc=" "+_ressources.getString("images");
    if(composant==Composant.COMPOSANT_LINEAIRE){
    sc=" "+_ressources.getString("lineaires");
    if(composant==Composant.COMPOSANT_METAD){
    sc=" "+_ressources.getString("lotdonnees");
    if(composant==Composant.COMPOSANT_NGS){
    sc=" "+_ressources.getString("nongraphiques");
    if(composant==Composant.COMPOSANT_SURFACIQUE){
    sc=" "+_ressources.getString("surfaciques");
    if(composant==Composant.COMPOSANT_SYMBOLIQUE){
    sc=" "+_ressources.getString("symboliques");
    s=_ressources.getString("liste_composant")+sc;
    else{
    s=_ressources.getString("description_composant");
    JLabel lab = new JLabel(s,JLabel.CENTER);
    JPanel inter = new JPanel(new GridLayout(1,1));
    inter.add(lab);
    inter.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),BorderFactory.createEtchedBorder()));
    Box boite1 = Box.createVerticalBox();
    boite1.add(inter);
    boite1.add(sc1);
    _inter.add(boite1);
    //ajout du deuxieme tableau
    _donAttCompTM=this.creeModeleDonnee2(composant);
    _donAttCompTM.addTableModelListener(this);
    setTableau2(new JTable(_donAttCompTM));
    getTableau2().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    getTableau2().getSelectionModel().addListSelectionListener(this);
    getTableau2().addMouseListener(((OngletDonnees)((OngletDonnees)getIHM().getOngletDonnees())).getOngletComposants());
    //ComboBox pour saisir le type de l'attribut
    _typeA = new JComboBox();
    _typeA.addItem(TypeEtendu.DATE.getNom());
    _typeA.addItem(TypeEtendu.DOMAINE.getNom());
    _typeA.addItem(TypePrimitif.ENTIER.getNom());
    _typeA.addItem(TypePrimitif.LOGIQUE.getNom());
    _typeA.addItem(TypePrimitif.REEL.getNom());
    _typeA.addItem(TypePrimitif.TEXTE.getNom());
    (getTableau2().getColumnModel().getColumn(3)).setCellEditor(new DefaultCellEditor(_typeA));;
    //renderer pour la colonne des nom qui indique en gras l'attribut identifiant
    getTableau2().getColumnModel().getColumn(1).setCellRenderer(new AttributTableCellRenderer(_composantCourant));
    Dimension d2 = new Dimension(_largeur ,(getNbLigne2()*16));
    JScrollPane sc2 = new JScrollPane(getTableau2());
    sc2.setViewportView(getTableau2());
    _inter.createVerticalStrut(16);
    inter = new JPanel(new GridLayout(1,1));
    lab = new JLabel(_ressources.getString("attributs"),JLabel.CENTER);
    inter.add(lab);
    inter.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),BorderFactory.createEtchedBorder()));
    Box boite2=Box.createVerticalBox();
    boite2.add(inter);
    boite2.add(sc2);
    _inter.add(boite2);
    if((composant.getPere()!=null)&&(composant.getPere()!=Composant.COMPOSANT)){
    this.add(_inter,BorderLayout.CENTER);
    else{
    this.add(_inter,BorderLayout.NORTH);
    public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm =(ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
    else {
    int ligneSel = lsm.getMinSelectionIndex();
    if(e.getSource()==getTableau2().getSelectionModel()){
    String alias = (String) _donAttCompTM.getValueAt(ligneSel,1);
    attribut = composantCourant.getAttribut(alias);
    else if(e.getSource()==getTableau1().getSelectionModel()){
    VectorTableModel vtm = null;
    int i = 0;
    if(_donCompApTM != null){
    vtm = _donCompApTM;
    if(_donCompPereApTM != null){
    vtm = _donCompPereApTM;
    i =1;
    if(vtm != null){
    String alias = (String) vtm.getValueAt(ligneSel,i);
    composantSelectionne= modele.getComposant(alias);
    else{
    composantSelectionne=composantCourant;
    I hope it make sens,
    thanks.

  • Problem in Array of JCheckBox

    I am facing a problem with the array of JCheckBox. Without array it works but when I use array it gives NullPointerException. No compile time error. I am using Null Layout. But I need to use the array. How can I solve this?
    Here is the code.
    JCheckBox jCheckBox_Questions[] = new JCheckBox[3];
    JCheckBox box = new JCheckBox();
    Dimension d[] = new Dimension[3] ;
    String strQuestions[] = {"No Child ?","Jaundice ?","Migraine ?"};
    int j=20,k=150;
    // This works
    box.setText(strQuestions[0]);
    add(box);
    d[1]= box.getPreferredSize();
    box.setBounds(j,k,d[1].width,d[1].height);
    k=k+20;
    //When I add the follwing fragment it gives NullPointerException
    jCheckBox_Questions[0]. setText(strQuestions[1]);// in this line
    add(jCheckBox_Questions[0]);
    d[2]= jCheckBox_Questions[0].getPreferredSize();
    jCheckBox_Questions[0].setBounds(j,k,d[2].width,d[2].height);

    Hi,
    classic error: in fact the code
       JCheckBox jCheckBox_Questions[] = new JCheckBox[3]; doesn't instantiate the checkboxes, it's only allocating 3 memory pointers (inited to null), ready to receive the futures instances of checkboxes. So you should have typed:
       JCheckBox jCheckBox_Questions[] = new JCheckBox[3];
       // Here we create the 3 objects
       for (int i=0;i<3;i++) jCheckBox_Questions[ i ] = new JCheckBox();
       //...Hope this will help,
    Regards.

  • Problem with Icon in JCheckBox

    I have a problem with a JCheckBox, when I assign an Icon to it, the checkBox dissapears and the only thing I see is the Icon. Is there a way to have the CheckBox and the Icon?
    Thanks
    Alejandro

    class MyCheckBox extends JPanel {
      JCheckBox jcb = new JCheckBox();
      JLabel jl;
      public MyCheckBox(String s, Icon i) {
        add(jcb);
        jl = new JLabel(s,i, JLabel.LEFT);
        add(jl);
      public boolean isSelected() { return jcb.isSelected(); }
      public void setSelected(boolean b) { jcb.setSelected(b); }
      public String getText() { return jl.getText(); }
      public void setText(String s) { jl.setText(s); }
      public Icon getIcon() { return jl.getIcon(); }
      public void setIcon(Icon i) { jl.setIcon(i); }
    }

  • PROBLEM IN JCHECKBOX FOCUS

    hi
    i don't get focus on checkbox.I need focus on the checkbox not on the text with it.what should i do?i sending my code please help me.
    public class SECOND extends javax.swing.JFrame {
    public SECOND() {
    initComponents();
    setSize(500, 500);
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    private void initComponents() {
    jTextField1 = new javax.swing.JTextField();
    jCheckBox1 = new javax.swing.JCheckBox();
    jButton1 = new javax.swing.JButton();
    getContentPane().setLayout(null);
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    getContentPane().add(jTextField1);
    jTextField1.setBounds(70, 60, 170, 21);
    getContentPane().add(jCheckBox1);
    jCheckBox1.setBounds(80, 120, 70, 15);
    jButton1.setText("OK");
    getContentPane().add(jButton1);
    jButton1.setBounds(100, 170, 90, 25);
    pack();
    public static void main(String args[]) {
    new SECOND().show();
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JTextField jTextField1;

    Hi,
    There's a number of ways to deal with this problem:
    1. Write an anonymous class that overides paintComponent() in the JCheckBox.
    2. Write an explicit class that extends JCheckBox and overrides paintComponent().
    3. Write a class that extends BasicCheckBoxUI and overrides paintFocus(). Tell the UIManager to use this class for all JCheckBoxes.
    Which method should you use?
    1 if there is only one JCheckBox in the whole application that you wish to have this functionality. (I personally prefer not to use anonymous classes).
    2 if there is a number of places you need this behaviour.
    3 If you would like every instance of JCheckBox (even its subclasses) to have this functionality.
    Hope that helps,
    Muel.

  • JCheckBox clicking problem in JTable

    Hi,
    I have a column of JCheckBox in a JTable. The JTable is only used to layout the controls(for lagecy reason). The JCheckBox has an item change listener attached. The problem is that OCCASIONALLY when the JCheckBox[i] was clicked, the debug in itemStateChanged show the source object was NOT JChechBox, it was JCheckBox[i+1] or JCheckBox[i-1]. In other word, it was the check box in the previous or next row changed state.
    Has anybody experienced similar problems? Is it a problem of JTable dispatching mouse click event?
    How to solve the problem?
    Thanks

    I'm not sure why you get the results you do, but instead of adding a change listener to the JCheckBox you could add a TableModelListener to the TableModel. This will fire an event whenever any data is changed. This thread shows a simple example:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=425540

  • Problem with JCheckBoxMenuItem/JCheckBox

    Hi guys, basically, I have this JCheckBoxMenuItem to set if another frame is always on top or not. But the problem is when I clicked that JCheckBoxMenuItem, the isSelected() method always returned false, even when it is selected. I think it might be I'm using the wrong event handler or there's some mechanism behind it that I'm not aware of. Or because the state is not updated instantly? I had the similar problem with my JCheckBox. Thanks very much for your help in advance!
        private void jCheckBoxMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
            //set up if robot view is always on top
            if(jRadioButtonMenuItem2.isSelected()){
                rvf.setAlwaysOnTop(true);
                System.out.println("true");
            } else{
                rvf.setAlwaysOnTop(false);
                System.out.println("false");
        }    Cheers,
    J
    Edited by: J.T on Jan 30, 2008 3:10 AM

    sorry guys i'm just being stupid hehe
    if(jRadioButtonMenuItem2.isSelected()){this should be jCheckBoxMenuItem2............. i'm sorry for posting a stupid question.
    thanks anyways.
    j.

  • Problem with JTable with JCheckBox as Header

    Hi,
    We have a JCheckBox as JTable Header. And respective data in that column also check boxes. For data check boxes, just i am sending Boolean object to object[][] data array. I am getting check Boxes as data components.
    For Header, i have create a TableRender object which is returning JCheckBox.
    Here my problem is,
    1) When i select a Header check box, all the check boxes are getting selected.
    2) Now we can reselect an data Check Box. When i reselect any data checkBox, Header CheckBox should be reselected. This is not happening. I was tried lot. Can any body give a solution to solve this problem.
    Please .... Please ...
    Thanks
    Mohan

    just call this method with null param on the JTable
    table.setTableHeader(null);
    cheers
    krishna

  • JCheckBox rollback problem.. Urgent

    Hi All,
    I hv 2 JChkbox and 2JTextField. I want the prev state of the JCheckBox when the cancel button is clicked.
    Ex:
    I hv Maximum value and Minimumvalue checkboxes.
    When the checkbox is not selected I'm enabling the corresponding textboxes.
    The problem is, When i open my panel and the Chk boxes is selected and i deselect both the chkboxes. I enter min valu = 10 and max val = 5 and i click the cancel button. Now when i click the cancel the chkboxes sh go to prev state as they are when the panel is opened.
    Is there any way to trace it out or any methods to it.
    Kindly help me. As it is very Urgent.
    Thnks in advance
    SS

    Isn't it a simple matter of remembering the state of the check boxes etc (in other words their 'model' data) when the dialog is popped up and then restoring them to that state if cancel is pressed?

  • Problem with Jcheckbox

    Hi friends;
    I need a small help. I want to change the property of a button based on the checkbox selected or deselected value.
    My problem is :
    if checkbox is selected then disable the button else
    if checkbox is deselected then enable the button.
    if(createLoginCKB.setEnabled(true)
    button1.setEnabled(false)
    else
    button1.setEnabled(true)
    But i am getting an error in the first line saying cannot convert void to boolean.
    Please help
    thanks
    Ad

    Use the isSelected() method to check if your checkbox is selected:
        if( createLoginCKB.isSelected() )
        ...."How to Use Check Boxes":
    http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#checkbox

  • JCheckBox as nodes in JTree having problems with custom renderer and editor

    Ok, let me give some background. I have an XML document that I am parsing and reading in as a JTree. Works fine.
    Next, I have overwritten the DefaultTreeCellEditor to return a JCheckBox and in this implementation of the getTreeCellEditorComponent(), I actually tell the node that he is selected. Works great.
    Next, I have overwritten the DefaultTreeCellRenderer to return a JCheckBox and in the implementation of the getTreeCellEditorComponenet, I actually check to see if the Node is selected in the tree based upon the isSelected state of the actual Tree Node set in the tree cell editor, and if so, I set the JCheckBox to selected(true).Works Great.
    Now, here is the issue. If a node in the tree is selected that contains children, then I want all of the children of that node to also be selected. However, when I select a node with children only the selected node is changed, and then a few moments later, the system repaints the entire tree and ALL nodes int the tree are set to a selected state. Strange? Yes. Any ideas?? WONDERFUL!! :)
    Here is the TreeCellEditor code:
    public Component getTreeCellEditorComponent(JTree tree,
    Object value,
    boolean isSelected,
    boolean expanded,
    boolean leaf,
    int row)
    elementCheckBox_ = new JCheckBox();
    Component result = null;
    System.out.println("isSelected? Editor = " + isSelected);
    TreePath newPath = tree.getPathForRow(row);
    System.out.println("value = " + value.getClass().toString());
    if(value instanceof IMarketTreeNodeElement)
    if(isSelected)
    if(((IMarketTreeNodeElement)value).isSelected())
    ((IMarketTreeNodeElement)value).setSelected(false);
    else
    ((IMarketTreeNodeElement)value).setSelected(true);
    elementCheckBox_.setSelected(isSelected);
    return elementCheckBox_;
    Here is the TreeCellRenderer code:
    public Component getTreeCellRendererComponent(JTree tree,
    Object value,
    boolean selected,
    boolean expanded,
    boolean leaf,
    int row,
    boolean hasFocus)
    Color colSelBorderCol = UIManager.getColor
    ("Tree.selectionBorderColor");
    selBorder_ = BorderFactory.createLineBorder(colSelBorderCol, 1);
    normBorder_ = BorderFactory.createEmptyBorder(1,1,1,1);
    elementCheckBox_.setText(value.toString());
    if(selected)
    elementCheckBox_.setSelected(selected);
    elementCheckBox_.setForeground(Color.YELLOW);
    elementCheckBox_.setBackground(Color.RED);
    else
    elementCheckBox_.setForeground(tree.getForeground());
    elementCheckBox_.setBackground(tree.getBackground());
    if (hasFocus)
    elementCheckBox_.setBorder(selBorder_);
    else
    elementCheckBox_.setBorder(normBorder_);
    return elementCheckBox_;
    Here is the Node Code setting all child nodes to selected:
    public void setSelected(boolean selected)
    isSelected_ = selected;
    if(isSelected_)
    if((this.getTagName() == "MARKET") ||
    (this.getTagName() == "TIER") &&
    (this.getChildCount() != 0))
    selectChildren(true);
    else
    if((this.getTagName() == "MARKET") ||
    (this.getTagName() == "TIER") &&
    (this.getChildCount() != 0))
    selectChildren(false);
    public boolean isSelected()
    return isSelected_;
    public void selectChildren(boolean selected)
    int children = getChildCount();
    for(int i = 0; i < children; i++)
    IMarketTreeNodeElement elem = (IMarketTreeNodeElement)
    this.getChildNodes().item(i);
    isSelected_ = selected;
    Thanks for any help! :-)

    I tried to run your sample code and it won't compile. The header files:
    #include
    #include
    #include
    #include
    #include
    do not exist on my install of MeasurementStudio. I am a bit suspicous that I don't have the latest and greatest (loading the dialong resouce gave version warnings). Here is one of my header file headers:
    //==============================================================================
    // Title : NiAxes3d.h
    // Copyright : National Instruments 1999. All Rights Reserved.
    // Purpose : Defines the CNiAxes3D class.
    //==============================================================================
    I
    looked on your updates site and don't really see an update that applies to ComponentWorks or MeasurementStudio. My version per the MAX program for 3DControls is 3.5.549.
    Do I need a newer version? What do I have to do to get the updated version? What does it cost?
    Chuck

  • Problem in Adding JCheckBox Object to JTable

    I want to add a JCheckBox Object to A JTbale Coloumn but it shows the following message in JTable Coloumn-
    javax.swing.JCheckBox[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@f9f9d8,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=false,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=].
    Help Me in solving this problem

    Hi,
    All the thing you have to do is to return a boolean for the column. JTable will use a checkbox (as default) to show boolean values.

  • Java Swing application problem in Windows vista

    When we execute the Swing application in windows vista environment.
    The look and feel of the swing components are displayed improperly.
    Do we need to put any specific look and feel for windows vista environment or any specific hardware configuration is required to setup windows vista environment.
    Please give some inputs to solve the problem.
    We have tried with the following sample code to run in windows vista.
    * Vista.java
    * Created on December 5, 2006, 5:39 PM
    public class Vista extends javax.swing.JFrame {
    /** Creates new form Vista */
    public Vista() {
    initComponents();
    pack();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
    jButton1 = new javax.swing.JButton();
    jToggleButton1 = new javax.swing.JToggleButton();
    jPanel1 = new javax.swing.JPanel();
    jCheckBox1 = new javax.swing.JCheckBox();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jTextField1 = new javax.swing.JTextField();
    getContentPane().setLayout(null);
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jButton1.setText("Button 1");
    getContentPane().add(jButton1);
    jButton1.setBounds(20, 20, 170, 30);
    jToggleButton1.setText("Togle btn");
    getContentPane().add(jToggleButton1);
    jToggleButton1.setBounds(100, 80, 90, 20);
    jPanel1.setLayout(null);
    jCheckBox1.setText("jCheckBox1");
    jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jPanel1.add(jCheckBox1);
    jCheckBox1.setBounds(10, 40, 130, 13);
    getContentPane().add(jPanel1);
    jPanel1.setBounds(10, 150, 200, 130);
    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane1.setViewportView(jTextArea1);
    getContentPane().add(jScrollPane1);
    jScrollPane1.setBounds(210, 150, 164, 94);
    jTextField1.setText("jTextField1");
    getContentPane().add(jTextField1);
    jTextField1.setBounds(240, 30, 140, 30);
    pack();
    }// </editor-fold>//GEN-END:initComponents
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new Vista().setVisible(true);
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;
    // End of variables declaration//GEN-END:variables
    }

    When we execute the Swing application in windows
    vista environment.
    The look and feel of the swing components are
    displayed improperly.Improperly means what? You must be aware that Vista's native L&F certainly isn't supported yet.

Maybe you are looking for

  • Is There A Simple Text Editor/Composter & Line Art Plug-In Available

    Yes, I know it has been addressed in other posts in the past but I wanted to know if any new tools are available since the update to 3.XX, outside of open a picture in a "Book" project and adding text in a border or downloading BorderFX, neither of w

  • Macbook pro performing very poor due to Yosemite

    Hi, I bought macbook pro 2012 model just 10 days back. Unfortunately i got yosemite preinstalled. My macbook pro is performing very very poor now .. Please help me in this regard Problem description: Very slow performance EtreCheck version: 2.1.5 (10

  • Understand the technical base for Enterprise Services?

    Hi all, I am trying to understand what is the technical base for enterprise services and the restrictions when activating them. The best documents I have found are: Note 1566412 u2013 Enhancement package 6 for SAP ERP 6.0. Note 1359215 u2013 Technica

  • What is the best to test superdrive?

    Hello there; I, have tried to install windows 8.1 in my mac; OS X LIon 10.7.5. got ISO image in my dvd disc and when I was in the stage of installation it wont recognizie my ISO file in DVD Disc. So I, am thinking of purchasing Blue-ray drive. So the

  • Applying JASS on 1. Zone Boot

    Hi, we are using JET (Jumpstart Enterprise Toolkit) to install our machines. This also installs JASS, our drivers and executes our driver on the machine. But we have now two problems. When creating a Zone just the Plain Jass package gets installed, o