How to eliminate the external white border from a Java applet when it is integrated into an HTML webpage

As someone experienced in dotnet, I decided to venture into creating a Java applet for my application. After successfully developing and signing the applet, it functioned perfectly within my application.

However, one issue perplexed me - when I attempted to embed it into an HTML file (in this case, a .cshtml file), a mysterious white border appeared around the applet which was not part of the HTML styling.

I made several attempts to remove the border without success. The applet solely consisted of a button adorned with an Icon, with its border property set to EmptyBorder.

A screenshot of the button viewed in the browser displayed a prominent Dx, representing the Java applet, encircled by a glaringly visible white border.

The HTML implementing the applet looked like this:

<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>

In addition, I applied the following CSS, although no resolution was achieved:

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

I also inserted the subsequent code in the init method of the applet:

jButton1 referenced the Dx button.

jButton1.setBorder(null);
jButton1.setBorder(BorderFactory.createEmptyBorder());

Unfortunately, even this adjustment did not alleviate the issue.

I am at a loss as to what step I have missed or where I might be going wrong. Any insights would be greatly appreciated.

To provide further context, here is the concise version of the applet code: https://gist.github.com/anonymous/1f31a97b68d34a5821e9

Answer №1

If your applet consists of one clickable area, using a JButton may not be necessary. Simply add a MouseListener to a JPanel and you're good to go. The extra features that come with a JButton, like shading and hover behavior, are more suited for GUI applications rather than a simple applet meant to process a single click.

Your issue is likely due to using the Nimbus Look and Feel. Sometimes autogenerated code can cause unwanted effects because it performs tasks without your explicit command.

The JComponent documentation mentions this problem when trying to set borders:

Although technically possible to set the border on any JComponent object, many standard Swing components' look and feel don't work well with user-set borders.

Overwriting the border isn't successful because it conflicts with the Nimbus LaF settings.

An easy solution: avoid using the Nimbus LaF by removing related code from the init() method.

A better approach: ditch the JButton and utilize a JPanel to handle clicks along with a JLabel to display your image. Since you don't require JButton behavior, opt for this method. While it may take more effort (like centering the JLabel), it's the correct way to proceed. Basically, transform jButton1 into a JLabel and your code will function as needed.

Here's a screenshot showcasing the outcome:

I didn’t refine the layout or color of the JLabel solution, so it may not appear as polished. However, notice there are no borders on the second or third applets.

For further details, check out: The Swing source code, Border with rounded corners & transparency, and Java rounded corners on JFrame?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Block Button styles not displaying in IE when set to Full Width

I can't figure out why, but it seems to be functioning properly on every other internet platform except this one. The first picture shows the button in IE, the second contains the code, and the third displays the button in Chrome. https://i.sstatic. ...

What are the steps to retrieve information from a raw HTML document?

Can data be extracted from a poorly written HTML file without IDs or classes? For example, if there is an unstructured saved HTML file of a profile webpage and I want to extract specific information like 'hobbies', can PHP be used for this task? ...

The transition effect of changing opacity from 0 to 1 is not functioning properly in Firefox

Having some trouble with this animation not working in Firefox. I'm triggering the animation using JavaScript after a delay like so: document.getElementById('my_id').style.webkitAnimationPlayState = "running"; I've also attempted: s ...

Is it possible to change the IP address for a domain directly from a Java program?

Is it possible to automate the process of redirecting a URL to a specific IP address without manually editing host entries in the system hosts file? Ideally, looking for a way to achieve this within an automation script written in JAVA. ...

In what way and where does Selenium convert Java or other high-level programming language commands into native JavaScript in order to interact with the browser?

While Javascript is essential for interacting with browser elements, Selenium offers APIs for various high-level programming languages such as Java and C#. How does Selenium handle these java commands when the code is not written in javascript? Is there ...

Extracting Data from Imgur Videos: Measuring their Duration

Hey there! Lately, I've been faced with the challenge of extracting specific information from videos hosted on the imgur website. Specifically, I'm interested in retrieving the video length indicated in the attached image. Despite my best efforts ...

What is the widely used term for the container that allows for panning by dragging with a mouse?

I am looking to design a container that extends beyond the width of the page, allowing users to pan by dragging through empty space between controls without zooming in or out. What is this type of container control typically referred to as? I am intereste ...

Custom sized box causing Bootstrap Navbar to be unresponsive

I am having trouble loading the Bootstrap 3 navbar inside a .box class with specific CSS rules: .box { height: 600px; width: 320px; position: relative; border: 2px solid #eee; } Unfortunately, it is not displaying re ...

Ensure to verify the input's value by clicking the button

Upon clicking a button, I am trying to determine if there is any content in an input field. However, it seems that the check only happens once when the website first loads. Subsequent clicks of the button do not detect any new input values entered into the ...

When using jquery.hide() and show(), the content within the div disappears momentarily before reappearing

Hello! I am experiencing an issue where the content of my div disappears after using a jQuery hide() and show() function. It seems to be gone. <li class="gg3"><a class="link" href="#" data-rel="content3">Link1</a></li> <div clas ...

Troubleshooting MaterialUI: Is there a way to prevent the InputLabel text from disappearing when setting a background color on the Select component?

My goal is to change the background color on dropdown elements while keeping the default text visible. Currently, if I don't explicitly set a background color on the Select component, the text specified in the InputLabel displays correctly. However, o ...

Elevate a division within its container

Is there a way to make a smaller div positioned at the top when it's placed next to a larger one in the same container? I'm looking for a solution that doesn't involve using position-relative and manually adjusting the placement. Take a loo ...

Close button situated at the top-right corner overlapped by HTML/CSS styling

Currently attempting to position a button overlapping and extending outside of its parent div, much like the illustration provided. However, my current efforts result in the button being contained within the parent DIV. The visual reference below showcases ...

When designing responsive websites in Bootstrap 4, what is the preferred choice between using the class "container" or "container-fluid"?

When creating responsive designs, which is more effective to use - the .container class or the .container-fluid class? ...

What is the best way to display time in EJS?

Currently facing an issue with formatting a time retrieved from the database. The value is strictly a time and not associated with any date. I've attempted to use getHours and getMinutes in EJS, but they don't seem to be functioning as expected. ...

Firefox does not allow contenteditable elements to be edited if they are nested inside a parent element that is draggable

Here is a basic HTML example: <div draggable=true> <div contenteditable=true>can't edit me</div> </div> When testing in Chrome, I noticed that I was able to edit the contents of the contenteditable div, however, this functi ...

Conceal excessive content on elements set in a stationary position

How can we prevent overflow of a fixed div within a container? Initially, I attempted nesting fixed elements inside each other, but that did not solve the issue. The only solution that comes to mind is using "inverted" masks: other fixed divs that hide eve ...

What is the best way to display DT elements next to each other?

Here is a link to the code snippet: http://jsfiddle.net/ZcdkT/1/ The code renders as: DT-nameA DD-definitionA 1 DT-nameB DD-definitionB 1 DD-definitionB 2 I would like it to be formatted like this: DT-nameA DT-nameB DD-definitionA 1 ...

Looking for a seamless way to convert jsp code to html using sightly in AEM 6.1?

I need help transforming JSP code to HTML using Sightly in AEM. In the JSP code, we have a scriptlet that stores a value from the dialog into a JSP variable called "coltype" using the code pageContext.setAttribute("coltype", xssAPI.filterHTML(properties. ...

JsonMappingException - Invalid character found in field name

Trying to deserialize a JSON format "{mapping:{MyType(type=\"A\", value=\"B\"):\"C\"}}" into the following class types: class MyMapping { Map<MyType, String> mapping; } class MyType { String type; Strin ...