Remove outer white border in a java applet when embedded inside an HTML page -


i dotnet guy , trying create java applet application. have been able create applet , working fine in application after signed it.

the issue have when embed html file (in case .cshtml file), see white border around applet , not style in html.

i've been trying rid of border not able it. applet contains button has icon it. thats control , i've set border property of button emptyborder

here's screen shot of button when view in browser.
dx button image
notice dx in screen shot. dx java applet , can notice white border around it.

here's html

<applet width="55" height="40" border="0"          codebase="~/content/my/applet"          id="dxapplet" name="dxapplet"          code="dxapplet.class"          archive="dxbuttonapplet.jar">     <param name="boxborder" value="false">      @html.raw(viewbag.appletparameters) </applet> 

additionally added following css didn't either.

applet:focus {     outline: none;     -moz-outline-style: none; }  

i've added following code in init method of applet

jbutton1 name of dx button.

jbutton1.setborder(null); jbutton1.setborder(borderfactory.createemptyborder()); 

but hasn't helped either.

can please tell me going wrong?

here's stripped down applet code: https://gist.github.com/anonymous/1f31a97b68d34a5821e9

if whole applet 1 clickable area, wouldn't use jbutton @ all. register mouselistener on jpanel , you're go. jbutton comes number of "features" shading , hover behavior that's great in gui app, not want in applet who's sole purpose process single click.

the problem you're running because you're using nimbus , feel. if didn't know doing that, that's problem auto-generating code - things didn't ask to.

the documentation .setborder() mentions issue:

although technically can set border on object inherits jcomponent, , feel implementation of many standard swing components doesn't work user-set borders.

so attempts overwrite border aren't doing because asked swing use nimbus laf.

easy fix: don't use nimbus laf; delete nimbus-related code init().

better fix: don't use jbutton, use jpanel listen clicks , jlabel display image. don't want behavior of jbutton, don't use it. little more effort (you have center jlabel) it's "right" way it, , can turn jbutton1 jlabel , code work.

here's screenshot of ended seeing:

screenshot of 3 different versions of applet; original, nimbus-disabled, , jlabel instead of jbutton

i didn't bother tweaking layout , color of jlabel solution doesn't nice, can see there's no borders on either second or third applet.

some more references: the swing source code (take @ jbutton , abstractbutton; lot of work don't need here), border rounded corners & transparency, , java rounded corners on jframe?


Comments