|
|
Re: html text in disabled label
|
Posted: Sep 21, 2005 6:19 AM
|
|
public class DisableTest extends javax.swing.JFrame {
public DisableTest() {
getContentPane().setLayout(new java.awt.FlowLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabDisableThis = new javax.swing.JLabel("<html>This is Line 1<br>This is Line2</html>");
jLabNotWorking = new javax.swing.JLabel("no new line is created here\nThis should be the next line");
jTgBtnDisabler = new javax.swing.JToggleButton("Disable both Labels");
jTgBtnDisabler.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
boolean disabled = evt.getStateChange() == evt.SELECTED;
jLabDisableThis.setEnabled(!disabled);
jLabNotWorking.setEnabled(!disabled);
}
});
getContentPane().add(jLabDisableThis);
getContentPane().add(jLabNotWorking);
getContentPane().add(jTgBtnDisabler);
pack();
}
public static void main(String[] args) {
new DisableTest().setVisible(true);
}
private javax.swing.JLabel jLabDisableThis;
private javax.swing.JLabel jLabNotWorking;
private javax.swing.JToggleButton jTgBtnDisabler;
}
This simple example crates 2 labels and a TogggleButton. This button sets both labels to disabled, so the text should be changed to the default color for disabled labels.
Of course the simplest solution would be to use 2 labels and get rid of the html text, but I need this method for a complex form created dynamically according to recordsets in a database and I don't want to make it more complicated then it allready is.
|
|