Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4252173
Votes 0
Synopsis Inability to reuse the HorizontalSliderThumbIcon
Category java:classes_swing
Reported Against 1.2
Release Fixed 7(b27)
State 10-Fix Delivered, request for enhancement
Priority: 4-Low
Related Bugs
Submit Date 07-JUL-1999
Description


I have the following source code to consider:

import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.UIManager;

public class vtcSlider extends JComponent
{
    public vtcSlider()
    {
	this(0, 0, 100);
    }

    public vtcSlider(int orientation)
    {
	this(orientation, 0, 100);
    }

    public vtcSlider(int min, int max)
    {
	this(0, min, max);
    }

    public vtcSlider(int orientation, int min, int max)
    {
	super();
	_slider = new JSlider(orientation);
	_icon = UIManager.getIcon("Slider.horizontalThumbIcon");

	setLayout(null);
    }
    
    public void paint(Graphics g)
    {
	_icon.paintIcon(_slider, g, 0, 0);

	// Why can't I do the following instead?
	// _icon.paintIcon(this, g, 0, 0);
    }
    
    public static void main(String[] args)
    {
	JFrame frame = new JFrame();

	vtcSlider slider = new vtcSlider();

	frame.getContentPane().add(slider);
	frame.pack();
	frame.setVisible(true);
    }

    //
    // Public data member section
    //

    //
    // Private data member section
    //
    private JSlider
	_slider;

    private Icon
	_icon;
}

What I wanted to do is to reuse the HorizontalSliderThumbIcon class
from one of the xxxIconFactory (xxx can be Metal, Motif, or Windows).
I can get an instance of this class by using the UIManager.getIcon(String)
method.  However, to draw this icon I would have to pass an
instance of JSlider into the paintIcon(Component, Graphics, int, int)
method.  It won't take my vtcSlider (for lack of a better name)
component.  I have looked at the HorizontalSliderThumbIcon.paintIcon(...)
method and the reason it won't take my vtcSlider component is 
because there is a line that casts a Component to JSlider.
However, the code in that method does not depend on whether a 
Component is a JSlider  customer  or not.  So why is the class casting
necessary?

I am using Windows NT 4.0 with patch 3.
(Review ID: 54979) 
======================================================================
Posted Date : 2005-09-19 16:25:28.0
Work Around
N/A
Evaluation
This seems like a reasonable request. There is nothing specific to the JSlider that justified the cast in MetalIconFactory. The methods used are hasFocus() and isEnabled() - both of which are defined in Component.
  xxxxx@xxxxx   2001-11-16
Contribution-Forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=12162&forumID=1463
Posted Date : 2006-03-21 03:03:00.0

To remove casting component to JSlider from MetalIconFactory. Other xxxIconFactories don't contain such functionality at all.
Posted Date : 2008-04-23 17:12:42.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang