簡體   English   中英

Java Swing Applet-無法設置背景顏色

[英]Java Swing Applet- Cant set background color

我是Swing的新手,首先。 我試圖設置錄音小程序的背景顏色,使其與我的網頁混合(白色而不是默認的灰色),但似乎永遠不會改變。 繼承人applet初始化......

public void init()
{
    setLayout(null);
    setBackground(Color.white);
    JLabel recorder = new JLabel("Record");
    JLabel fileName = new JLabel("Please Enter File Name");
    JLabel status = new JLabel("Status...");
    fnametxt = new JTextField("FileNameHere");
    statustxt = new JTextField("");
    record = new JButton("Record");
    play = new JButton("Play");
    pause = new JButton("Pause");
    stop = new JButton("Stop");
    send = new JButton("Upload");
    listen = new JButton("Listen");
    save = new JButton("Save and Submit");
//A bunch of other stuff, event listeners and whatnot.

我沒有使用布局管理器,我手動設置所有位置。 有任何想法嗎?

您(可能)設置了Applet的背景,但該背景僅顯示其未被其他組件阻擋的位置。

根據您構建GUI的方式,可能會有內部面板或覆蓋該區域的其他組件。 您也需要更改這些組件的顏色(或者使用setOpaque(false)將它們設置為透明)。

編輯:setOpaque()僅適用於Swing組件,而不適用於Applet本身(因為這是普通的舊AWT)。

您可能應該設置內容窗格的背景顏色。

如果您在applet中使用JPanel,則還必須為JPanel的內容窗格着色。 以下代碼將JPanel本身及其內容窗格的背景設置為白色:

setBackground(Color.white);
getContentPane().setBackground(Color.white); //Color JPanel

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM