Skip to main content

XP L&F only bug with J[Toggle]Button border setting - fixed for 1.4.2final?

4 replies [Last post]
quarkdoll
Offline
Joined: 2003-09-15

hi -

this is a general Swing issue, but it's only being seen on the XP L&F (1.4.2beta), so i'm putting it under this forum. so compiling and running the below class code on XP using 1.4.2beta will produce a button that has a border regardless of mouse location.
The behaviour should be a borderless button unless the mouse has entered its bounds rectangle, where upon it gets a border for the time the mouse is in the rectangle.

Can someone at Sun verify for me whether this is fixed in the upcoming release already - if not, i'll submit it as a bug.

thanks,
loki

</p>
<p>---snip-snip---<br />
import java.awt.*;<br />
import java.awt.event.*;</p>
<p>import javax.swing.*;<br />
import javax.swing.border.*;</p>
<p>public class RolloverWonk<br />
    extends JFrame<br />
    implements MouseListener {</p>
<p>    static protected Border BUTTON_EMPTY_BORDER = new EmptyBorder(2, 2, 2, 2);<br />
    static protected Border BUTTON_DEFAULT_BORDER = (new JToggleButton()).getBorder();</p>
<p>    protected JToggleButton woeToggleButton;</p>
<p>    public RolloverWonk () {<br />
        super("Rollover \"Woe\"");</p>
<p>        this.buildPanel();<br />
    }</p>
<p>    protected void buildPanel () {<br />
        JPanel pane = new JPanel();</p>
<p>        this.woeToggleButton = new JToggleButton("Woe");<br />
        this.woeToggleButton.setBorder(BUTTON_EMPTY_BORDER);<br />
        this.woeToggleButton.addMouseListener(this);<br />
	this.woeToggleButton.setMaximumSize(new Dimension(150, 150));</p>
<p>        pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));<br />
        pane.add(this.woeToggleButton, BorderLayout.CENTER);<br />
	pane.setBorder(new EmptyBorder(60, 60, 60, 60));<br />
	pane.setPreferredSize(new Dimension(275, 275));</p>
<p>	this.getContentPane().add(pane);<br />
	this.pack();</p>
<p>        this.setLocationRelativeTo(null);<br />
        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);</p>
<p>        this.addWindowListener( new WindowAdapter () { public void windowClosing (WindowEvent we) {<br />
								System.exit(0);<br />
							}<br />
						     });<br />
    }</p>
<p>    /**<br />
     *<br />
     * MouseListener implementation<br />
     *<br />
     */<br />
    public void mouseClicked (MouseEvent me) { }</p>
<p>    public void mouseEntered (MouseEvent me) {<br />
        if (! this.woeToggleButton.isSelected()) {<br />
            this.woeToggleButton.setBorder(BUTTON_DEFAULT_BORDER);<br />
        }<br />
    }</p>
<p>    public void mouseExited (MouseEvent me) {<br />
        if (! this.woeToggleButton.isSelected()) {<br />
            this.woeToggleButton.setBorder(BUTTON_EMPTY_BORDER);<br />
        }<br />
    }</p>
<p>    public void mousePressed (MouseEvent me) { }</p>
<p>    public void mouseReleased (MouseEvent me) { }</p>
<p>    static public void main (String[] args) {<br />
        try {<br />
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<br />
        } catch (Exception e) {<br />
            System.err.println("Unable to set look and feel");<br />
        }</p>
<p>	RolloverWonk rw = new RolloverWonk();</p>
<p>	rw.show();<br />
    }</p>
<p>}</p>
<p>

Message was edited by: jeff -- added code tag

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous

First let me say that it behaves fine on Mac OS X.

Second, it is a bit ugly to copy and paste code formatted with the code tag in the edior unter OS X. Nearly evera line has a character \160 which causes compile errors. Does it work with Windows / Linux correctly?

viravan
Offline
Joined: 2003-06-23

Works for me on Windows XP Pro with 1.4.2beta.

;o)

V.V.

quarkdoll
Offline
Joined: 2003-09-15

yeah, i know there's no problem under osX nor win2k, nor xp using not the xp l&f... viravan - take out the UI setting line, recompile, and note the difference in behaviour... do you see a difference?

it could be agrued that because xp _must_ draw its buttons to look different than the background, then setting the border like i'm doing should behave as it does currently.

to this i'd say that osX is behaving correctly in this case -- that a button with no border should look just like text (or an icon) on the background. in osX we don't see a borderless aqua blob, but rather no button - it should be the same in xp.

viravan
Offline
Joined: 2003-06-23

>take out the UI setting line, recompile, and note the difference in behaviour

Ok, now I see the difference... with the line removed, the button looks just like a plain old label.

Hmmmm... it's a good test case for bug reporting.

;o)

V.V.