-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0, 1.3.1
-
beta
-
x86, sparc
-
windows_98, windows_nt
Name: krT82822 Date: 03/19/2000
19 Mar 2000, eval1127@eng -- possibly a dupe of 4282567.
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
I created a new Button called RectangularButton that extends JButton. I was
working fine with jdk1.2.2 and jdk1.3 BETA, However when I complied it with
jdk1.3 ORC1 [it] displays very strange behavior:
getModel().isArmed() always returns true.
Please try to compile the code below first using the either jdk1.2.2 OR
jdk1.3 "BETA" and another time using jdk1.3 ORC1 in both cases try to move the
mouse so that it rolls over the button without pressing it, in both cases see
the color change and the System.out.println outputs.
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.event.*;
public class RectangularButton extends JButton implements
MouseMotionListener,MouseListener{
BasicStroke stroke = new BasicStroke(0.1f);
int i =0;
public RectangularButton(String label) {
super(label);
setFont(new Font("Copperplate Gothic Bold",Font.BOLD,9));
setBackground(new Color(143,143,175));
Dimension size = getPreferredSize();
setPreferredSize(size);
addMouseMotionListener(this);
addMouseListener(this);
setContentAreaFilled(false);
}
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (getModel().isArmed()) {
System.out.println("ARMED and setting color to gray");
g.setColor(Color.gray);
}
else if(i == 0){
System.out.println("NOT ARMED and setting color to RGB 207 207 224");
g.setColor(new Color(207,207,224));
}
else{
System.out.println("NOT ARMED and setting color to RGB 207 207 255");
g.setColor(new Color(207,207,255));
}
g.fill3DRect(1,1, getSize().width - 1, getSize().height -1, true);
super.paintComponent(g2);
}
protected void paintBorder(Graphics g) {
//DRAW NOTHING
}
Shape shape;
public boolean contains(int x, int y) {
if (shape == null ||
!shape.getBounds().equals(getBounds())) {
shape = new Rectangle2D.Double(1, 1, getWidth(), getHeight());
}
return shape.contains(x, y);
}
public void mousePressed(MouseEvent e) {
System.out.println("Mose Pressed!!");
}
public void mouseDragged(MouseEvent e) { }
public void mouseMoved(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) {
System.out.println("Mouse Entered!!");
i=99;
Graphics g = getGraphics();
if(g != null){
paintComponent(g);
paintBorder(g);
}
}
public void mouseExited(MouseEvent e) {
System.out.println("Mose Exited!!");
i=0;
Graphics g = getGraphics();
if(g != null){
paintComponent(g);
paintBorder(g);
}
}
public void mouseClicked(MouseEvent e) {
System.out.println("Mose Clicked!!");
}
// TEST ROUTINE.
public static void main(String[] args) {
JButton button1 = new RectangularButton("Private Chat");
JButton button2 = new RectangularButton("Private Chat ");
JButton button3 = new RectangularButton("User Info ");
button1.setSelected(false);
(button1.getModel()).setArmed(false);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Buttton#1 hit!!!");
}
});
JFrame frame = new JFrame();
frame.getContentPane().add(button1);
frame.getContentPane().add(button2);
frame.getContentPane().add(button3);
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(300, 300);
frame.setVisible(true);
}
}
I hope this bug will be fixed soon, since I need to use one very important
thing in jdk1.3 ORC1.
(Review ID: 102638)
======================================================================
- duplicates
-
JDK-4323201 ChangeListener event generated when mouse rolls over component on 1.3 NT
- Closed
-
JDK-4486557 ButtonModel's isArmed(), isPressed() don't work as advertised
- Closed
- relates to
-
JDK-8341982 Simplify JButton/bug4323121.java
- Resolved