button changes when having focus
hi. i have a simple listener:
btnRemove.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent evt)
{
removeSelectedRow();
System.out.println("perss");
}
}
);
when the method removeSelectedRow() is commented the button (btnRemove) acts "normal", but when this method is active, whenever i hover over the button it looks as if it's been clicked. there is no mentioning of the button ANYWHERE ELSE IN THE CODE.
any ideas?
many thanks.
Shay.
[550 byte] By [
shayl] at [2007-9-26 1:30:33]

Hi. I figured my query will make more sense if I put the code, so have a look.
Once the applet is excecuted, the button clicked, and the dialog closed, whenever you go on and off the buttons area, the button will change it's color. It seems that the dialog is causing this somehow.
any ideas?
Thanks.
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.awt.*;
public class Tap extends JApplet {
Container pane =null;
public Tap() {
pane = getContentPane();
JButton jb1 = new JButton();
jb1.setBounds(10, 20, 50, 20);
jb1.setText("jb1");
pane.add(jb1);
jb1.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent evt)
{
f();
}
}
);
}
public void f(){
Object[] options = {"B"};
JDialog dialog =null;
JOptionPane optionPane = new JOptionPane("A" ,JOptionPane.INFORMATION_MESSAGE, JOptionPane.CLOSED_OPTION , null, options);
dialog = optionPane.createDialog(pane, "C");
dialog.setResizable(false);
dialog.show();
}
public void init(){
setBounds(10, 10, 400, 400);
}
}
the HTML file:
<HTML>
<HEAD>
</HEAD>
<body>
<!--"CONVERTED_APPLET"-->
<!-- CONVERTER VERSION 1.3 -->
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "400" HEIGHT = "400" ALIGN = "CENTER" codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
<PARAM NAME = CODE VALUE = Tap.class >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
</OBJECT>
</BODY>
</HTML>
shayl at 2007-6-29 1:28:50 >

hmm.. well, i now noticed that if i use actionlistener instead of the mouse adapter, it's working fine without the unwanted side effect. WHY?
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.awt.*;
public class Tap extends JApplet implements ActionListener {
Container pane =null;
JButton jb1 = null;
public Tap() {
pane = getContentPane();
jb1 = new JButton();
jb1.setBounds(10, 20, 50, 20);
jb1.setText("jb1");
pane.add(jb1);
jb1.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==jb1){
f();
}
}
public void f(){
Object[] options = {"B"};
JDialog dialog =null;
JOptionPane optionPane = new JOptionPane("A" ,JOptionPane.INFORMATION_MESSAGE, JOptionPane.CLOSED_OPTION , null, options);
dialog = optionPane.createDialog(pane, "C");
dialog.setResizable(false);
dialog.show();
}
public void init(){
setBounds(10, 10, 400, 400);
}
}
shayl at 2007-6-29 1:28:50 >
