Results 1 to 6 of 6
  1. #1
    Vase is offline Member
    Join Date
    Jan 2011
    Location
    Gainesville, FL
    Posts
    45
    Rep Power
    0

    Default Assigning labels to JSliders?

    Is it possible?

    I have 3 JSliders, each corresponding to a color (R,G,B) that adjust the background color of a JPanel. I would like to label these "Red", "Green", and "Blue", respectively. Outside of just creating JLabels and having them 'near' the JSliders, is there any way to do this?

    Thanks.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Outside of just creating JLabels and having them 'near' the JSliders, is there any way to do this?
    What is wrong with this approach?

    I guess you could always use a TitledBorder around the slider.

  3. #3
    santeron is offline Member
    Join Date
    Apr 2011
    Location
    Athens, Greece
    Posts
    52
    Rep Power
    0

    Default

    Well JLabel would be your first choice. Is there a specific reason why you don't want to use them?

  4. #4
    Vase is offline Member
    Join Date
    Jan 2011
    Location
    Gainesville, FL
    Posts
    45
    Rep Power
    0

    Default

    I wanted to add labels above the sliders, and with the size of the panel and layout manager, it always places them to the left of the slider (or to the right if added after).

    I guess this was preemptive, though; it works fine to the side, so no need for it above.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You can put the JLabels wherever you want if you use the right layout managers, and Swing constants when creating the JLabel. For instance, if you want a JLabel centered above a JSlider, check the API to see the constructor for creating a JLabel where the text is centered (it takes a String and an int, the latter being SwingConstants.CENTER). Then place the JSlider into a JPanel that uses BorderLayout into the BorderLayout.CENTER position and then add the JLabel into the same JPanel, BorderLayout.NORTH.

  6. #6
    santeron is offline Member
    Join Date
    Apr 2011
    Location
    Athens, Greece
    Posts
    52
    Rep Power
    0

Similar Threads

  1. Printing labels to A4
    By eggy524 in forum New To Java
    Replies: 3
    Last Post: 09-23-2010, 05:53 PM
  2. size och swt labels
    By larsk in forum SWT / JFace
    Replies: 0
    Last Post: 10-04-2009, 01:01 PM
  3. How do I sent font of labels in an array?
    By Exhonour in forum New To Java
    Replies: 9
    Last Post: 01-14-2009, 04:48 PM
  4. Working with Labels on Panels.
    By vargihate in forum AWT / Swing
    Replies: 2
    Last Post: 01-04-2008, 05:09 AM
  5. Aligning Labels
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 07:26 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
  •