0

I found this project which works just fine in a standalone run. However when I try to add it to a JPanel in another project (already did this in the exact same project but with a JFrame of my own and worked fine) this error arises:

 UIDefaults.getUI() failed: no ComponentUI class for: doubleslider.MThumbSlider[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,isInverted=false,majorTickSpacing=0,minorTickSpacing=0,orientation=HORIZONTAL,paintLabels=false,paintTicks=false,paintTrack=true,snapToTicks=false,snapToValue=true]
    java.lang.Error
        at javax.swing.UIDefaults.getUIError(UIDefaults.java:729)
        at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:130)
        at javax.swing.UIDefaults.getUI(UIDefaults.java:759)
        at javax.swing.UIManager.getUI(UIManager.java:1002)
        at javax.swing.JSlider.updateUI(JSlider.java:323)
        at doubleslider.MThumbSlider.updateUI(MThumbSlider.java:44)
        at javax.swing.JSlider.<init>(JSlider.java:275)
        at javax.swing.JSlider.<init>(JSlider.java:182)
        at doubleslider.MThumbSlider.<init>(MThumbSlider.java:24)
        at doubleslider.DoubleSlider.<init>(DoubleSlider.java:29)
        at com.einge.scadaremotecontrol.Ventana.<init>(Ventana.java:227)
        at com.einge.scadaremotecontrol.ScadaRemoteControl.<init>(ScadaRemoteControl.java:92)
        at com.einge.scadaremotecontrol.ScadaRemoteControl.main(ScadaRemoteControl.java:197)
    UIDefaults.getUI() failed: no ComponentUI class for: doubleslider.MThumbSlider[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,isInverted=false,majorTickSpacing=0,minorTickSpacing=0,orientation=HORIZONTAL,paintLabels=false,paintTicks=false,paintTrack=true,snapToTicks=false,snapToValue=true]
    java.lang.Error
        at javax.swing.UIDefaults.getUIError(UIDefaults.java:729)
        at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:130)
        at javax.swing.UIDefaults.getUI(UIDefaults.java:759)
        at javax.swing.UIManager.getUI(UIManager.java:1002)
        at javax.swing.JSlider.updateUI(JSlider.java:323)
        at doubleslider.MThumbSlider.updateUI(MThumbSlider.java:44)
        at doubleslider.MThumbSlider.<init>(MThumbSlider.java:26)
        at doubleslider.DoubleSlider.<init>(DoubleSlider.java:29)
        at com.einge.scadaremotecontrol.Ventana.<init>(Ventana.java:227)
        at com.einge.scadaremotecontrol.ScadaRemoteControl.<init>(ScadaRemoteControl.java:92)
        at com.einge.scadaremotecontrol.ScadaRemoteControl.main(ScadaRemoteControl.java:197)

My first guess is that the MultiTumbSlider class is trying to set a different Look&Feel than my JFrame. Any solutions? I couldn't figure this out and I really need two sliders so to have a time Range

Any help will be appretiated!

rMaero
  • 195
  • 4
  • 13

2 Answers2

3

I don't recognize the loading approach used in this very old example; it appear to be based on the current Look & Feel. You might try setting javax.swing.plaf.metal.MetalLookAndFeel explicitly. Going forward, look at Kirill Grouchnikov's How to Write a Custom Swing Component for guidance on modernizing the delegate plumbing.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I played around with updateUI() method found on the MThumbSlider class to load the L&F. With that I manage to get rid of the error but still the slider is missing in my program. The only way I found to make this slider appear is using a button to show up another JFrame with the slider, that and changing my program's L&F to metal did work. But I want to show the slider inside a JPanel in my main window. I am giving up this example as it took several hours and nothing concrete is coming. Do you have any other approaches to make a double Slider (or a "range" slider)? – rMaero Jul 18 '12 at 11:57
  • I followed Kirill's guide successfully. Sorry I have nothing better. – trashgod Jul 18 '12 at 19:19
  • A related example from that archive is examined [here](http://stackoverflow.com/a/18242040/230513). – trashgod Aug 18 '13 at 22:12
1

At the book "Java Swing, 2nd Edition", by Marc Loy et. al., at the section "Creating Your Own Component" (Chapter 28: Swing Under the Hood), we have the code line at the main() method:

UIManager.put(JogShuttleUI.UI_CLASS_ID, "BasicJogShuttleUI");

This will inform the UIDefaults, through UIManeger, the class name of the basic UI delegate of the custom component. Note, however, that you must provide the fully qualified class name, since it will be located by the class loading mechanism.

For example, when I'm use

UIManager.put(DiagramUI.UI_CLASS_ID, "BasicDiagramUI");

I get the same error reported by your question. But, when I change it to

UIManager.put(DiagramUI.UI_CLASS_ID, BasicDiagramUI.class.getName());

Things works pretty well. Nice coding!

ranieribt
  • 1,280
  • 1
  • 15
  • 33