Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I do not want that my button is selected...  RSS feed

 
DanielCosta Sobrinho
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...
I have a simple program...
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class teste extends JFrame
{
JButton botao;
public teste()
{
botao = new JButton("Dainel");
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(botao);
}
public static void main(String[] args)
{
teste t = new teste();
t.setSize(200, 200);
t.show();
}
}
How I make it JButton not to be selected? To around take off that line of the button???
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just call setFocusable( false ) on the botao JButton.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to what Nate said, you can setFocusPainted(false) if you never want to see that Focus Square at all. Probably not good practice to do this, but I do it anyway.
 
DanielCosta Sobrinho
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank people...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!