我處於應用程序的中間,背景看起來很平坦。 我已經嘗試設置使用我的知識的代碼,僅僅是這一個背景:設置背景顏色[JAVA]
frame.getContentPane().setBackground(Color.BLUE);
全:
JFrame frame = new JFrame("HC Navigator");
frame.setVisible(true);
frame.setSize(250, 200);
frame.getContentPane().setBackground(Color.BLUE); // Colour Set Here
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
現在,當我啓動,它打開了一個藍色的背景,但隨後的窗口一旦它加載按鈕/ Jpanels,背景將回到純白色。
主面板/ JFrame的代碼:
package me.jamplifier;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.text.DefaultCaret;
public class Launcher extends JFrame {
// Main Class Area (Default/Main Windows)
public Launcher(){
// Main Window
JFrame frame = new JFrame("HC Navigator");
frame.setSize(250, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// Text Labels
JLabel label = new JLabel("Beta 1.5 ");
JLabel label1 = new JLabel("Welcome to HurricaneCraft");
JPanel panel = new JPanel();
frame.add(panel);
panel.add(label);
panel.add(label1);
Font font = new Font("Verdana", Font.BOLD, 12);
label1.setFont(font);
label1.setForeground(Color.RED);
label.setFont(font);
label.setForeground(Color.GRAY);
// Buttons
JButton site = new JButton("Site");
site.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
openWebPage("http://www.hurricanecraft.com");
}
});
JButton forums = new JButton("Forums");
forums.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
openWebPage("http://www.hurricanecraft.com/forums/");
}
});
JButton apps = new JButton("Member Apps");
apps.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
openWebPage("http://hurricanecraft.freeforums.org/member-registration-f29.html");
}
});
JButton community = new JButton("Community");
community.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
createFrame2();
}
});
JButton admin = new JButton("Admin Area");
admin.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
createFrame();
}
});
JButton update = new JButton("Update Log");
update.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
createFrame1();
}
});
panel.add(site);
panel.add(forums);
panel.add(community);
panel.add(apps);
panel.add(admin);
panel.add(update);
}
place'frame.setVisible(true);'最後,看看會發生什麼。 –
爲了得到更好的幫助,儘早發佈[SSCCE](http://sscce.org/) – Reimeus
不起作用。它仍然加載背景,然後被按鈕和麪板取代。 – Jahshua