I want to put an Image at the NORTH CENTER. As of now it is at the north, but I cannot seem to center it. Can someone please show me how to center the north image.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Matt
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mario {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
EventQueue.invokeLater(new Runnable()
{
public void run()
{
QuizFrame frame = new QuizFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class QuizFrame extends JFrame
{
public QuizFrame()
{
//size the frame
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
//create Icon object and set its location
ImageIcon icon = new ImageIcon("C:\\users\\Matt\\Documents\\mario2.gif");
//create a label
JLabel label = new JLabel();
//add the icon to the label
label.setIcon(icon);
JButton button1 = new JButton("one"); //create button
JButton button2 = new JButton("two"); //create button
JButton button3 = new JButton("three");//create a button
JButton button4 = new JButton("four"); //create a button
//create a panel
QuizPanel = new JPanel();
//add the label to the north border of the panel
[COLOR="Red"] add(label,BorderLayout.NORTH); //I want this to be NORTH CENTER[/COLOR]
QuizPanel.add(button1);
QuizPanel.add(button2);
QuizPanel.add(button3);
QuizPanel.add(button4);
add(QuizPanel,BorderLayout.SOUTH);
QuizLabel = new JLabel("This is a test",JLabel.CENTER);
add(QuizLabel,BorderLayout.CENTER);
}
private JPanel QuizPanel;
private JLabel QuizLabel;
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 200;
}


Sign In
Create Account


Back to top










