Creating Control Buttons with NetBeans IDE - The nucleus of JCheckBox
(Page 4 of 5 )
This is the continuation of the previous section. Further proceeding we have the following:
private void btnShowActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
repaintTextBox();
}
The above code is the heart of our application. According to the code in the previous section, you can understand that when the button is hit, the JRE tries to execute "btnShowActionPerformed." The implementation for that method is as above. According to the above code, the event would simply execute another method, "repaintTextBox."
"repaintTextBox" is my own method, which is defined below:
private void repaintTextBox() {
int style=0;
if (this.chkBold.isSelected()) {
style += java.awt.Font.BOLD;
}
if (this.chkItalic.isSelected()) {
style += java.awt.Font.ITALIC;
}
this.txtMsg.setFont(this.txtMsg.getFont().deriveFont(style));
}
The above would simply test which check box is switched on (by using "isSelected") and apply the respective font style (bold or italic). This is very similar to what happened when we used the toggle buttons. The only issue is that the changes would not come about unless the "show" button is hit (unlike the previous example, in which they were automatic).
Next: Working with JRadioButton >>
More Java Articles
More By Jagadish Chaterjee