Results 1 to 5 of 5
  1. #1
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Quick & Simple Question about JLabels.

    Sorry I had to make a thread about this but no online help was straight-forward enough for this simple problem.

    Very easy question, I'm making JLabels. I've made an etched JLabel. I just want to know how to give it color? Example;

    Java Code:
    label2.setPreferredSize(new Dimension(100, 20));
        label2.setOpaque(true);
        label2.setBackground(Color.BLUE);
        label2.setForeground(Color.BLACK);
        label2.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
    What is the method to color your etched borders?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Quick & Simple Question about JLabels.

    I'll move this to the AWT/Swing forum which is where you'll get the best help.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Quick & Simple Question about JLabels.

    From the API docs: "If no highlight/shadow colors are initialized when the border is created, then these colors will be dynamically derived from the background color of the component argument passed into the paintBorder() method".

    As suggested by that, use the constructor that allows you to set both the highlight and shadow colours as well as the fact that you want it RAISED.

  4. #4
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Re: Quick & Simple Question about JLabels.

    Ah, you're right. All I had to do was add this one line of code.

    Java Code:
    label2.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.YELLOW, Color.BLACK));
    Just needed to add highlighting and shadowing. Thanks for the guidance!

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Quick & Simple Question about JLabels.

    You're welcome.

Similar Threads

  1. Quick simple question.
    By FnL7676 in forum New To Java
    Replies: 14
    Last Post: 03-08-2011, 12:26 AM
  2. Really quick question
    By shadycharacter in forum New To Java
    Replies: 2
    Last Post: 04-22-2010, 10:06 PM
  3. Quick question about this simple code..
    By shroomiin in forum New To Java
    Replies: 2
    Last Post: 11-10-2009, 05:58 PM
  4. quick question
    By vouslavous in forum Java Applets
    Replies: 4
    Last Post: 04-24-2009, 08:35 PM
  5. Simple version of quick sort
    By Java Tip in forum Algorithms
    Replies: 0
    Last Post: 04-15-2008, 07:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •