java - setBorderPainted(boolean) not working -


jpanel droppan = new jpanel ();  droppan.setlayout (new flowlayout ());   bi1 = new imageicon (""); b1 = new jbutton (bi1); //b1.setborderpainted (false); b1.setborder (borderfactory.createemptyborder (2,3,2,3)); b1.setcontentareafilled (false); b1.setsize (100,38); //b1.setbounds(3,3,100,38);  droppan.add(b1); b1.addmouselistener (this);  add(droppan); 

this row of buttons code above snippet of first button. initially, first button has border unless click on button , button has border, if "transfers" if mean.

what doing wrong? setborderpainted comment because if it's not in comment border still there

this panel inside frame

i "think" talking focus border used show button has focus...

try using b1.setfocuspainted(false); instead

for example...

import java.awt.borderlayout; import java.awt.eventqueue; import java.awt.flowlayout; import javax.swing.borderfactory; import javax.swing.imageicon; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.uimanager; import javax.swing.unsupportedlookandfeelexception;  public class buttonrows {      public static void main(string[] args) {         new buttonrows();     }      public buttonrows() {         eventqueue.invokelater(new runnable() {             @override             public void run() {                 try {                     uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname());                 } catch (classnotfoundexception | instantiationexception | illegalaccessexception | unsupportedlookandfeelexception ex) {                 }                  jframe frame = new jframe("testing");                 frame.setdefaultcloseoperation(jframe.exit_on_close);                 frame.setlayout(new flowlayout());                  (int index = 0; index < 10; index++) {                     jbutton b1 = new jbutton(integer.tostring(index));                     b1.setfocuspainted(false);                     b1.setborder(borderfactory.createemptyborder(2, 3, 2, 3));                     b1.setcontentareafilled(false);                      frame.add(b1);                 }                  frame.pack();                 frame.setlocationrelativeto(null);                 frame.setvisible(true);             }         });     }  } 

also, use of setsize , setbounds scary, should letting layout manager deal these details.

i don't know why you're using mouselistener on button, prefered method gaining notification when button triggered through actionlistener interface, button triggered via number means, not mouse click

take closer @ how use buttons more details


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -