1

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.

enter image description here

Image of the Issue

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();

}

}

Frakcool
  • 10,915
  • 9
  • 50
  • 89
M. Amadou
  • 15
  • 4
  • *I've attached a photo of that better explains the issue I'm having below.* a [Runnable Example](http://stackoverflow.com/help/mcve) explains it better. Remember that: "An image says more than 100 words but your code says more than 100 images" :) – Frakcool Jan 07 '16 at 19:20
  • Added a runnable example – M. Amadou Jan 07 '16 at 19:30
  • If you are able to get rid of insets and have a good result on Windows, X11 and OS X, I'm very curious to see how it was done :) – Rhangaun Jan 07 '16 at 19:36
  • Those "insets" appear because you're using `JButtons`s and this kind of components have borders by default. – Titus Jan 07 '16 at 19:36
  • When I say inset I mean the grey thing around the border of the whole JPanel – M. Amadou Jan 07 '16 at 19:40
  • oh, I see, I think those are caused because you haven't set any background color to the `menus` panel, try this: `menus.setBackground(new Color(53, 9, 9));` – Titus Jan 07 '16 at 20:33
  • Nope that didn't help sadly :/ – M. Amadou Jan 07 '16 at 22:20
  • @Rhanagun when instantiating MigLayout do new Miglayout("insets 0"); it worked for me!! – M. Amadou Jan 07 '16 at 22:30

2 Answers2

1

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.

Amber
  • 2,413
  • 1
  • 15
  • 20
0

Just set the insets to be 0 in the layout constraint, like "insets 0".

WesternGun
  • 11,303
  • 6
  • 88
  • 157