0

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

Trey Carey
  • 143
  • 1
  • 8

1 Answers1

0

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.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104