The Artima Developer Community
Sponsored Link

Java Answers Forum
html text in disabled label

2 replies on 1 page. Most recent reply: Sep 21, 2005 6:19 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

html text in disabled label Posted: Sep 16, 2005 3:36 AM
Reply to this message Reply
Advertisement
In a JLabel I need a line break.
The only way I know to do this is to use html text for the label.

Now I also need to disable the label.

The problem is that the labels text does not change color if I do so?

Is there a way to fix this or do I have to change the color manually?

Can I do something else than using html?


lalama fodie toure

Posts: 11
Nickname: lalama11
Registered: Nov, 2004

Re: html text in disabled label Posted: Sep 21, 2005 5:33 AM
Reply to this message Reply
Please send your code we'll see what we can do to fix the trouble
best regard

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: html text in disabled label Posted: Sep 21, 2005 6:19 AM
Reply to this message Reply
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.

Flat View: This topic has 2 replies on 1 page
Topic: javaxswing message dialog TABLE please help Previous Topic   Next Topic Topic: Save text file with images

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use