Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:02:51+00:00 2026-06-05T18:02:51+00:00

I have this custom JSlider, which will be used in many other forms/windows. But

  • 0

I have this custom JSlider, which will be used in many other forms/windows. But when i use MyJSlider it shows the following style:

enter image description here

Expected output was:

enter image description here

YumYumYum.java:

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class YumYumYum {

  private JFrame f = new JFrame();

  public YumYumYum() {

    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    MyJSlider slider = new MyJSlider();
    JPanel p = new JPanel();
    p.add(slider);    

    f.getContentPane().add(p);
    f.setSize(320, 240);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        new YumYumYum();
      }
    });
  }
}

MyJSlider.java:

import javax.swing.*;
import javax.swing.plaf.synth.SynthLookAndFeel;

public class MyJSlider extends JSlider {

  public MyJSlider() {    
    try {
      SynthLookAndFeel laf = new SynthLookAndFeel();
      laf.load(MyJSlider.class.getResourceAsStream("/demo.xml"), MyJSlider.class);
      UIManager.setLookAndFeel(laf);
    } catch (Exception e) {
      e.printStackTrace();
    } 
    setOrientation(JSlider.VERTICAL);
    setMinimum(-24);
    setMaximum(12);
    setVisible(true); 
  }

}

demo.xml:

<synth>
    <style id="backingStyle">
        <opaque value="TRUE"/>
        <font name="Dialog" size="12"/>
        <state>
            <color value="WHITE" type="BACKGROUND"/>
            <color value="BLACK" type="FOREGROUND"/>
        </state>
    </style>
    <bind style="backingStyle" type="region" key=".*"/>

    <style id="SliderTrackStyle">
        <opaque value="TRUE"/>
        <state>
            <color type="BACKGROUND" value="ORANGE"/>
        </state>
    </style>
    <bind style="SliderTrackStyle" type="region" key="SliderTrack" />

    <style id="SliderThumbStyle">
        <opaque value="TRUE"/>
        <state>
            <color type="BACKGROUND" value="RED"/>
        </state>
        <state value="PRESSED">
            <color type="BACKGROUND" value="GREEN"/>
        </state>

    </style>
    <bind style="SliderThumbStyle" type="region" key="SliderThumb" />
</synth>

Follow up:

final MyJSlider veryFirst= new MyJSlider(); // Hide first one: Style is not showing
final MyJSlider vSlider0 = new MyJSlider(); // Style - starts
final MyJSlider vSlider1 = new MyJSlider();
final MyJSlider vSlider2 = new MyJSlider();
final MyJSlider vSlider3 = new MyJSlider();    
final MyJSlider vSlider4 = new MyJSlider();    
final MyJSlider vSlider5 = new MyJSlider();  
final MyJSlider vSlider6 = new MyJSlider();
final MyJSlider vSlider7 = new MyJSlider();    
final MyJSlider vSlider8 = new MyJSlider(); 
final MyJSlider vSlider9 = new MyJSlider(); // Style - continue....

// JPanel
MyJSliderPanel eqPanel = new MyJSliderPanel();     
// Hide the first one always. As it does not shows the Style
eqPanel.add(veryFirst);    

vSlider0.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider0);

vSlider1.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider1);

vSlider2.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider2);

vSlider3.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider3);

vSlider4.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider4);

vSlider5.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider5);

vSlider6.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider6);

vSlider7.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider7);

vSlider8.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider8);

vSlider9.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent ce) {
    eq();
  }
});
eqPanel.add(vSlider9);
eqPanel.setSize(100, 100);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:02:53+00:00Added an answer on June 5, 2026 at 6:02 pm

    You need to set the look and feel before creating any GUI components.. E.g: You are calling:

    UIManager.setLookAndFeel(laf);
    

    ….to late.


    Example (using your demo.xml):

    public class Test {
    
        public static void main(String[] args) {
    
            try {
                SynthLookAndFeel laf = new SynthLookAndFeel();
                laf.load(Test.class.getResourceAsStream("demo.xml"), Test.class);
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                e.printStackTrace();
            }
    
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            f.add(new JSlider() {{
                setOrientation(JSlider.VERTICAL);
                setMinimum(-24);
                setMaximum(12);
                setVisible(true);
            }});
            f.setSize(320, 240);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
    }
    

    Outputs the correct screenshot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this custom textbox that I am working on and I can use
I have used this custom grid view in my code, and I want to
I have this table, which can be seen as a basic custom gantt chart:
I have a ListView which contains custom rows. This custom row has following UI
I have this custom class which extends EventDispatcher private var assetsManager:AssetManager; And this running
I have a custom UITableViewCell created in IB. All my cells will have this
Let's say I have this custom component. It subclasses JMenuItem and all instances use
I've been trying to center this custom view I have inside this other custom
I have this legacy database for which I'm building a custom viewer using Linq
I have used this custom Helper in My Razor View. @Html.Link(OpenewWindow, Constants.Value, new {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.