So I've been working on this for 2 days now, and I've gotten the basics of java.swing down (I hope, at least, as I started learning it to 2 days ago.) Anyhow, I successfully loaded a background image, but I can't seem to get the foreground one to work. I'm not sure what code you'll need, so I'll post all of it. And while you take a look at it, did I set up my JPanels correctly? (specifically the allContent and fourRows ones.)
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.util.*;
import junit.framework.Test;
public class MainFrame {
//Variables
private static final String IMAGE_PATH = "imageFolder/warlordsOrganizerBackground.png";
private static final String IMAGE_PATH2 = "imageFolder/warlordsLogo.png";
public static JFrame programFrame;
public static JLabel warlordsBackground;
public static JLabel warlordsLogo;
public static JPanel allContent;
public static JPanel fourRows;
public static JScrollPane scrollPane;
//Making the parts for the GUI
public static void createGUI(){
//programFrame Title and Layout
programFrame = new JFrame("Warlords Organizer");
programFrame.setLayout(new BorderLayout());
Icon backgroundIcon = new ImageIcon(IMAGE_PATH);
warlordsBackground = new JLabel(backgroundIcon);
File imageFile = new File(IMAGE_PATH);
File imageFile2 = new File(IMAGE_PATH2);
//Warlords Logo JLabel
Icon logoIcon = new ImageIcon(IMAGE_PATH2);
warlordsLogo = new JLabel(logoIcon);
//New JPanel for GridLayout
fourRows = new JPanel(new GridLayout(0,4));
fourRows.setLayout(new GridLayout());
//Makes the Initial BorderLayout (Using allContent JPanel)
allContent = new JPanel();
allContent.setLayout(new BorderLayout());
allContent.add(warlordsLogo, BorderLayout.NORTH);
allContent.setVisible(true);
allContent.add(fourRows, BorderLayout.CENTER);
//Add ScrollPane / MAKE SURE TO ADD TO new JScrollPane WHERE IT NEEDS TO BE / TEXT
scrollPane = new JScrollPane(allContent);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setOpaque(false);
scrollPane.getViewport().setOpaque(false);
//JFrame programFrame Constructors
programFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
programFrame.setContentPane(warlordsBackground);
programFrame.pack();
programFrame.setVisible(true);
programFrame.setResizable(false);
} // public static void createGUI() Closing
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createGUI();
} //public void run() Closing
});
}
}
And finally, my JScrollPane. I need to do something with that, so don't mind that. I set up my project files like this, if it helps any -
After I get my image working, I'll need to figure out how to get custom fonts (the BEBAS__.ttf) so if you also have some resources for that, I'd appreciate it.