java - how to remove space between jtextfield, jbutton and raisedbevel border -


i wants remove blank space or border space between jbutton , jtextfield added inside raisedbevel border tried code still gap between them

import java.awt.*;  import javax.swing.*; import javax.swing.border.border;  public class main {   public static void main(string args[]) {     jframe f = new jframe("jpasswordfield  ");     f.setdefaultcloseoperation(jframe.exit_on_close);     jpanel p=new jpanel(),pp=new jpanel();     jbutton b=new jbutton("o");  b.setborder(null); b.setborderpainted(false); b.setmargin(new insets(0,0,0,0));  border emptyborder = borderfactory.createemptyborder();     b.setborder(emptyborder);     border  raisedbevel=borderfactory.createraisedbevelborder();       pp.setborder(raisedbevel);     jtextfield t=new jtextfield(20);     t .setborder(javax.swing.borderfactory.createemptyborder());     t.setpreferredsize(new dimension(100, 25));     b.setpreferredsize(new dimension(25, 25));     pp.setbackground(color.black);     pp.add(t);       pp.add(b);        p.add(pp);     f.add(p);     f.setsize(400, 100);     f.setvisible(true);     } } 

i wants remove black space thanks.

jpanel use flowlayout default, uses padding of 5, vertically , horitzontially, default.

if want continue using flowlayout, specify padding want using like...

pp = new jpanel(new flowlayout(flowlayout.center, 0, 0); 

or use layout manager, gridbaglayout

i'd discourage using setpreferredsize , rely on border's , layout's affect how component might "extra" sized beyond default preferred size

have @ laying out components within container, how use flowlayout, how use gridbaglayout , should avoid use of set(preferred|maximum|minimum)size methods in java swing?


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -