JLabels have transparent background on Mac, but on windows they don't?

Trey Carey

I am making an application for my church, and my JLabels have some drop shadows on them, I'm trying to make the background transparent on a windows computer but it's not working. It works perfectly on a Mac, I have tried googling this and using setOpague to false but nothing, suggestions?

Images of the problem: Mac

Windows

Code:

//Made by Trey Carey | 6.25.18
//Credit to Daniel Kihlgren for the original idea
//Credit to Kevin Blenman for UI work

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

public class choosingScreen {
	static String versionNumber = new String("1.0"); //Version Number
	static String applicationName = new String("Lower Thirds SDV " + versionNumber); //Application Name
	
	public static void main(String[] args) throws IOException {
		createChoosingWindow();
	}

	static void createChoosingWindow() throws IOException {
		JFrame mainFrame = new JFrame(applicationName);
		
		//Images to Buffer
		URL icon = loginScreen.class.getResource("/images/SDV-Icon.png");
		JLabel backgroundImage = new JLabel(new ImageIcon(loginScreen.class.getResource("/images/Main_BKG.png")));
		JLabel logo = new JLabel(new ImageIcon(loginScreen.class.getResource("/images/POK Logo.png")));
		JLabel copyrightImage = new JLabel(new ImageIcon(loginScreen.class.getResource("/images/Copyright.png")));
		JLabel lowerThirdsLogo = new JLabel(new ImageIcon(loginScreen.class.getResource("/images/LowerThirds_Logo.png")));
		JButton lowerThirdsButton = new JButton(new ImageIcon(loginScreen.class.getResource("/images/Lower Thirds.png")));
		JButton lyricsButton = new JButton(new ImageIcon(loginScreen.class.getResource("/images/Lyrics.png")));
		
		BufferedImage iconImage = ImageIO.read(icon);
		
		mainFrame.add(backgroundImage);
		
		backgroundImage.add(lowerThirdsLogo);
		lowerThirdsLogo.setSize(lowerThirdsLogo.getPreferredSize());
		lowerThirdsLogo.setLocation(150, 20);
		
		backgroundImage.add(logo);
		logo.setSize(logo.getPreferredSize());
		logo.setLocation(270, 525);
		
		backgroundImage.add(copyrightImage);
		copyrightImage.setSize(copyrightImage.getPreferredSize());
		copyrightImage.setLocation(600, 550);
		
		backgroundImage.add(lowerThirdsButton);
		lowerThirdsButton.setSize(lowerThirdsButton.getPreferredSize());
		lowerThirdsButton.setLocation(200, 200);
		lowerThirdsButton.setText("");
		lowerThirdsButton.setBorder(BorderFactory.createEmptyBorder());
		
		backgroundImage.add(lyricsButton);
		lyricsButton.setSize(lyricsButton.getPreferredSize());
		lyricsButton.setLocation(200, 300);
		lyricsButton.setText("");
		lyricsButton.setBorder(BorderFactory.createEmptyBorder());
		
		//LYRICS ACTION LISTENER
		lyricsButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO add code for making Lyrics work
				
			}
	
		});
		
		//LOWER THIRDS ACTION LISTENER
		lowerThirdsButton.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				//TODO make code for working lower thirds here
			}
			
		});
		
		mainFrame.setResizable(false);
		mainFrame.setIconImage(iconImage);
		mainFrame.pack();
		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mainFrame.setLocationRelativeTo(null);
		mainFrame.setVisible(true);
	}
	
	

}

Here are the images

Luke Woodward

Following this question, try adding the following lines after the line JButton lyricsButton = ...:

        lowerThirdsButton.setContentAreaFilled(false);
        lowerThirdsButton.setBorder(BorderFactory.createEmptyBorder());
        lyricsButton.setContentAreaFilled(false);
        lyricsButton.setBorder(BorderFactory.createEmptyBorder());

You already have lines to set the borders of the buttons further down. You can delete these as they don't achieve anything any more.

You may then find that the buttons are off-centre. This is perhaps to be expected, given that the images are 381 pixels wide, your background image is 801 pixels wide and you are putting the images 200 pixels away from the left-hand side and hence 220 pixels away from the right. Putting them 210 pixels away from the left should address this.

Making this change to your code made the button borders disappear when run on Windows. I can't say what effect these changes would have on a Mac as I don't have one.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

png images with transparent background don't work in pygame 2.0.0

Windows in Gnome Metacity don't have shadows

Why Rethinkdb don't have binary for windows?

How to have transparent background for button?

Wireshark - you don't have permission to capture on that device mac

Mac OS don't have permission to usr/bin folder at all

You don't have permission to save file in Mac Mojave

JLabels and TextFields don't appear when declared in separate method/class

Windows Store App Transparent Background

Windows forms button background transparent

Vuejs fusioncharts have completely transparent background

Style table to have transparent background with opaque text?

jQuery Mobile - How to have a transparent background for the slider?

Make svg logo have transparent background

How to have a transparent figure with a darkgrid background in seaborn?

Why don’t I have the Get Windows 10 icon?

I have more info windows but maps don't display marker

plot(p) and plot(ggplot_gtable(ggplot_build(p))) don't seem to give same output when plot background is transparent

Have a legitimate Windows 7 license and the Windows 7 key but don't have the DVD

UIButton is transparent when I don't want it to be

Button hover don't work with transparent

Matplotlib: how to make the background transparent on Windows

Windows 10 transparent Icons on a white background

C# Windows Form Transparent Background Image

How to change a font/background color in transparent windows?

Ubuntu 14.10 Some windows with transparent background

Loading objects with assimp in OpenGL windows with transparent background

Bootstrap transparent panel css background: rgba won't get transparent

SSH connections running in the background don't exit if multiple connections have been started by the same shell