Skip to main content

Issue with JXColorSelectionButton using 0.9.5

6 replies [Last post]
ruanae
Offline
Joined: 2006-10-23
Points: 0

Hi

I've just upgraded from a fairly old version of SwingX (~ July 07) to the latest release (0.9.5). Most of the change over has been fine but I've run into an issue with JXColorSelectionButton.

When I use the old version of SwingX, I get a button with the coloured square showing the selected colour, which is great. Using the new version however I get a button displaying a black circle instead. I've tried with a few different versions of swingX (I have a build from ~ Feb 08) and it works fine, but with 0.9.5 its this strange circle.

I'm not sure if this is an issue in the build, or if there is now another jar I need to include or if there is something else wrong. Any help people could give me would be greatfully recieved.

Below is the most basic test case I could come up with, just the button on a JFrame. I would include screenshots showing the issue but I don't know how.

Thanks for your assistance.

<br />
/*<br />
 * Created by JFormDesigner on Wed Jan 07 11:36:27 GMT 2009<br />
 */</p>
<p>package swingX;</p>
<p>import java.awt.BorderLayout;<br />
import java.awt.Container;<br />
import java.awt.GridBagConstraints;<br />
import java.awt.GridBagLayout;<br />
import java.awt.Insets;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;</p>
<p>import javax.swing.BoxLayout;<br />
import javax.swing.JButton;<br />
import javax.swing.JFrame;<br />
import javax.swing.JPanel;<br />
import javax.swing.border.EmptyBorder;</p>
<p>import org.jdesktop.swingx.JXColorSelectionButton;</p>
<p>/**<br />
 * @author User #3<br />
 */<br />
public class TestFrame extends JFrame {<br />
	public TestFrame() {<br />
		initComponents();<br />
	}</p>
<p>	private void okButtonActionPerformed(ActionEvent e) {<br />
		System.exit(0);<br />
	}</p>
<p>	private void initComponents() {<br />
				dialogPane = new JPanel();<br />
		contentPanel = new JPanel();<br />
		panel1 = new JPanel();<br />
		xColorSelectionButton1 = new JXColorSelectionButton();<br />
		buttonBar = new JPanel();<br />
		okButton = new JButton();</p>
<p>		//======== this ========<br />
		Container contentPane = getContentPane();<br />
		contentPane.setLayout(new BorderLayout());</p>
<p>		//======== dialogPane ========<br />
		{<br />
			dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));<br />
			dialogPane.setLayout(new BorderLayout());</p>
<p>			//======== contentPanel ========<br />
			{<br />
				contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.X_AXIS));</p>
<p>				//======== panel1 ========<br />
				{<br />
					panel1.setLayout(new BoxLayout(panel1, BoxLayout.LINE_AXIS));</p>
<p>					//---- xColorSelectionButton1 ----<br />
					xColorSelectionButton1.setText("text");<br />
					panel1.add(xColorSelectionButton1);<br />
				}<br />
				contentPanel.add(panel1);<br />
			}<br />
			dialogPane.add(contentPanel, BorderLayout.CENTER);</p>
<p>			//======== buttonBar ========<br />
			{<br />
				buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));<br />
				buttonBar.setLayout(new GridBagLayout());<br />
				((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};<br />
				((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};</p>
<p>				//---- okButton ----<br />
				okButton.setText("Close");<br />
				okButton.addActionListener(new ActionListener() {<br />
					public void actionPerformed(ActionEvent e) {<br />
						okButtonActionPerformed(e);<br />
					}<br />
				});<br />
				buttonBar.add(okButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,<br />
						GridBagConstraints.CENTER, GridBagConstraints.BOTH,<br />
						new Insets(0, 0, 0, 0), 0, 0));<br />
			}<br />
			dialogPane.add(buttonBar, BorderLayout.SOUTH);<br />
		}<br />
		contentPane.add(dialogPane, BorderLayout.CENTER);<br />
		pack();<br />
		setLocationRelativeTo(getOwner());<br />
			}</p>
<p>	public static void main(String[] args)<br />
	{<br />
		TestFrame tf = new TestFrame();<br />
		tf.pack();<br />
		tf.setVisible(true);<br />
		tf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
	}</p>
<p>		private JPanel dialogPane;<br />
	private JPanel contentPanel;<br />
	private JPanel panel1;<br />
	private JXColorSelectionButton xColorSelectionButton1;<br />
	private JPanel buttonBar;<br />
	private JButton okButton;</p>
<p>}<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

The rectangle is the implementation for Mac platforms, where this button is from. There is no real corresponding formulation of this button on any other platform. As such, the default implementation is a colored circle.

JXColorSelectionButton is in terrible shape and has no real maintainer. Anyone interested in championing this component would be welcomed.

Karl

ruanae
Offline
Joined: 2006-10-23
Points: 0

Okay, I'm just wondering why it's gone from working nicely to now being a black circle. Especially as I'm working on a Windows Machine. I think I've got the two versions of the source code so I'm going to have a look into it to see what I can find out.

In terms of championing the component, I'm willing to share anything i find/fix but I'm afraid due to work load and other issues I dont really have the time currently. Or the technical knowledge.

ruanae
Offline
Joined: 2006-10-23
Points: 0

Right I've had a poke around in the source code. The button draws a circle because it's not MacOS, which is fine, the issue is why its a grey circle rather than a coloured circle.

Having had a look through, I'm wondering why, in the paint method the code for drawing the circle is:

[code]
Graphics2D g2 = (Graphics2D) g.create();

try {
g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
g.setColor(Color.LIGHT_GRAY);
final int DIAM = Math.min(getWidth(), getHeight());
final int inset = 3;
g2.fill(new Ellipse2D.Float(inset, inset, DIAM-2*inset, DIAM-2*inset));
g.setColor(FILL_COLOR);
final int border = 1;
g2.fill(new Ellipse2D.Float(inset+border, inset+border, DIAM-2*inset-2*border, DIAM-2*inset-2*border));
} finally {
g2.dispose();
}
[/code]

where it appears that the colour to use is set on the graphics instance g and the graphic instance g2 is used to draw the circle?

Replacing it with:

[code]

Graphics2D g2 = (Graphics2D) g.create();

try {
g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
g2.setColor(Color.LIGHT_GRAY);
final int DIAM = Math.min(getWidth(), getHeight());
final int inset = 3;
g2.fill(new Ellipse2D.Float(inset, inset, DIAM-2*inset, DIAM-2*inset));
g2.setColor(FILL_COLOR);
final int border = 1;
g2.fill(new Ellipse2D.Float(inset+border, inset+border, DIAM-2*inset-2*border, DIAM-2*inset-2*border));
} finally {
g2.dispose();
}
[/code]

seems to work and colours the circle the required colour (red by default)

Thanks

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Good catch. Please file a bug report and I'll make the correction to the g2 variable.

Karl

ruanae
Offline
Joined: 2006-10-23
Points: 0

Created the issue
https://swingx.dev.java.net/issues/show_bug.cgi?id=977

and assigned it to you. Hope thats okay.

Cheers.

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Fixed. Please verify.

Karl