java - How to get rid of the space around buttons in Nimbus LAF? -


i need put jbuttons in small place, , problem nimbus laf automatically puts space around them, , result buttons smaller are.

in following example program use flowlayout 0 horizontal , vertical gaps, , expected buttons sit tightly without space between them. if comment out setting of nimbus laf, behave expected.

import javax.swing.*; import java.awt.flowlayout;  public class nimbusspace {     public static void main(string[] args) {         swingutilities.invokelater(new runnable() {             @override             public void run() {                 buildgui();             }         });     }      private static void buildgui() {         try {             uimanager.setlookandfeel("javax.swing.plaf.nimbus.nimbuslookandfeel");         } catch (classnotfoundexception | instantiationexception | illegalaccessexception | unsupportedlookandfeelexception e) {             e.printstacktrace();         }          jframe f = new jframe("test");         f.setdefaultcloseoperation(windowconstants.exit_on_close);          jpanel p = new jpanel(new flowlayout(flowlayout.left, 0, 0));         p.add(createbutton("aa"));         p.add(createbutton("bb"));         p.add(createbutton("cc"));          f.add(p);         f.pack();         f.setlocationrelativeto(null);         f.setvisible(true);     }      private static jbutton createbutton(string text) {         jbutton b = new jbutton(text);  //        b.setborder(null); //        b.setborderpainted(false); //        b.setmargin(new insets(0,0,0,0)); //        b.putclientproperty("jcomponent.sizevariant", "large"); //        b.putclientproperty("jcomponent.sizevariant", "mini");  //        uidefaults def = new uidefaults(); //        def.put("button.contentmargins", new insets(0,0,0,0)); //        b.putclientproperty("nimbus.overrides", def);          return b;     } } 

as can see in commented out code in createbutton, tried quite few things, didn't remove space around buttons.

edit: based on discussions in comments, seems not possible remove space between rectangular edges of button , drawn rounded-rectangle outline. nimbus reserves these 2 pixels "focus highlight", , cannot changed without re-implementing lot of nimbus functionality.

so accepted guleryuz's trick: if buttons positioned @ overlapping , negative positions, can look bigger. in practice idea seems work, not clean solution, if know better (and reasonably implemented) solution, don't hesitate answer...

approach 1:

jpanel p = new jpanel(new flowlayout(flowlayout.left, -4, 0)); 

approach 2:

    jpanel p = new jpanel(new flowlayout(flowlayout.left, 0, 0));     p.add(createbutton("aa", 1));     p.add(createbutton("bb", 2));     p.add(createbutton("cc", 3)); 

with modifications in createbutton method

private static jbutton createbutton(string text, final int s) {     jbutton b = new jbutton(text){         @override         public void setlocation(int x, int y) {             super.setlocation(x-(s*4), y);         }     };     return b; } 

approach 3

jpanel p = new jpanel(new miglayout("ins 0, gap -5","[][][]")); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -