1 54 55 package com.mullassery.act.gui.components; 56 57 import java.awt.Dimension ; 58 59 import javax.swing.ButtonGroup ; 60 import javax.swing.JPanel ; 61 import javax.swing.JRadioButton ; 62 63 import com.mullassery.act.gui.TextData; 64 65 70 public class TBooleanField extends JPanel implements TextData { 71 private final ButtonGroup bg = new ButtonGroup (); 72 private final JRadioButton fl = new JRadioButton ("False"); 73 private final JRadioButton tr = new JRadioButton ("True"); 74 75 public TBooleanField() { 76 tr.setAlignmentY(TOP_ALIGNMENT); 77 fl.setAlignmentY(TOP_ALIGNMENT); 78 tr.setPreferredSize(new Dimension (fl.getPreferredSize().width, 15)); 79 fl.setPreferredSize(new Dimension (fl.getPreferredSize().width, 15)); 80 bg.add(tr); 81 bg.add(fl); 82 add(tr); 83 add(fl); 84 setPreferredSize(new Dimension (200, 20)); 85 } 86 87 public String getText() { 88 if (bg.isSelected(tr.getModel())) 89 return "true"; 90 if (bg.isSelected(fl.getModel())) 91 return "false"; 92 return null; } 94 95 public void setText(String txt) { 96 if (txt.equalsIgnoreCase("true")) { 97 bg.setSelected(tr.getModel(), true); 98 } else { 99 bg.setSelected(fl.getModel(), true); 100 } 101 } 102 103 } 104 | Popular Tags |