Reputation: 15
I'm using MigLayout to create a UI. My Question is, how do I get rid of the grey / whitish inset on the screen and make the whole background of the applet dark brown? (53, 9, 9)
I've attached a photo of that better explains the issue I'm having below.
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import net.miginfocom.swing.MigLayout;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Casino extends JFrame implements ActionListener {
private JButton start, settings, scenario, music;
//mainUI, startUI, settingsUI, scenarioUI, blackjackUI, oddorevenUI, tcmUI, overorunderUI, slotsUI;
/**
* Constructor method
*/
public Casino(){
JPanel mainUI, startUI, settingsUI, scenarioUI, blackjackUI, oddorevenUI, tcmUI, overorunderUI, slotsUI;
JPanel menus = new JPanel(new MigLayout());
MigLayout mig = new MigLayout();
mainUI = new JPanel(new MigLayout());
buildMainUI(mainUI);
menus.add(mainUI);
add(menus);
mig.layoutContainer(mainUI);
//Audio implementation Method 2(not mine)
Clip clip = null;
try {
clip = AudioSystem.getClip();
} catch (LineUnavailableException e1) {
e1.printStackTrace();
}
AudioInputStream inputStream = null;
try {
inputStream = AudioSystem.getAudioInputStream(new File("57.wav"));
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
clip.open(inputStream);
} catch (LineUnavailableException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
clip.loop(Clip.LOOP_CONTINUOUSLY);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
} // looping as long as this thread is alive
/* Audio code taken from
* http://stackoverflow.com/questions/8979914/audio-clip-wont-loop-continuously
*/
setSize(780, 700);
setResizable(false);
setLayout(mig);
setTitle("White Lily Casino");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
}
public void buildMainUI(JPanel mainUI){
getContentPane().add(mainUI);
mainUI.setBackground(new Color(53, 9, 9));
//Background items
JLabel title = new JLabel(new ImageIcon("title.png"));
mainUI.add(title, "dock north");
JLabel border = new JLabel(new ImageIcon("mainscreenborder.png"));
mainUI.add(border, "pos 0px 500px");
settings = new JButton();
ImageIcon s = new ImageIcon("settings-button.png");
settings.setBackground(new Color(53, 9, 9));
settings.setIcon(s);
mainUI.add(settings, "pos 300 200");
music = new JButton();
ImageIcon m = new ImageIcon("music-button.png");
music.setBackground(new Color(53, 9, 9));
music.setIcon(m);
mainUI.add(music, "pos 300 263");
scenario = new JButton();
ImageIcon sc = new ImageIcon("scenario-button.png");
scenario.setBackground(new Color(53, 9, 9));
scenario.setIcon(sc);
mainUI.add(scenario, "pos 300 326");
start = new JButton();
ImageIcon st = new ImageIcon("start-button.png");
start.setBounds(320, 404, 122, 63);
start.setBackground(new Color(53, 9, 9));
start.setIcon(st);
mainUI.add(start, "pos 300 389");
}
public void buildStartUI(JPanel startUI){
}
public void buildSettingsUI(JPanel settingsUI){
}
public void buildScenarioUI(JPanel scenarioUI){
}
public void buildBlackjackUI(JPanel blackjackUI){
}
public void buildOddOrEvenUI(JPanel oddorevenUIUI){
}
public void buildTCMUI(JPanel tcmUI){
}
public void buildOverOrUnderUI(JPanel overorunderUI){
}
public void buildSlotsUI(JPanel slotsUI){
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Casino wlc = new Casino();
}
}
Upvotes: 1
Views: 232
Reputation: 12738
Just set the insets to be 0 in the layout constraint, like "insets 0"
.
Upvotes: 0
Reputation: 2463
Just create one panel and set it as the JFrame's content pane.
Your sample is pretty complicated and not runnable since it has references to image and sound files... Here's a simple example that should give you a better idea of how to achieve what you want:
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
public class Casino extends JFrame
{
public Casino()
{
JPanel mainPanel = new JPanel (new MigLayout());
buildMainUI(mainPanel);
setContentPane(mainPanel);
setSize(780, 700);
setResizable(false);
setTitle("White Lily Casino");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void buildMainUI(JPanel mainUI)
{
mainUI.setBackground(new Color(53, 9, 9));
// Background items
JLabel title = new JLabel("Title");
title.setForeground(Color.CYAN);
mainUI.add(title, "dock north");
}
public static void main(String[] args)
{
Casino wlc = new Casino();
}
}
P.S. Since you're using miglayout there are better ways of positioning your buttons than with absolute coordinates. Check out the cheatsheet or quickstart guide.
Upvotes: 1