我試圖在右邊框中使JComponent
不透明。使JComponent不透明
我希望做一個對象與我的具體特點,所以我正在使用JComponent
,可以是不透明的
這是因爲我會讓一個圖書館,我不希望使用JPanel
或JLabel
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
public class ProbadorCodigos {
JFrame Frame=new JFrame();
JComponent BORDEDE=new JComponent() {private static final long serialVersionUID = 2222L;};
public ProbadorCodigos() {
Frame.setSize(500, 500);
Frame.setResizable(false);
Frame.setUndecorated(false);
Frame.setLayout(null);
Frame.setLocationRelativeTo(null);
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Frame.getContentPane().setBackground(Color.darkGray);
Format();
Action();
}
private void Format() {
BORDEDE.setBounds(Frame.getWidth()-100, 0, 100, Frame.getHeight());
BORDEDE.setOpaque(true);
BORDEDE.setVisible(true);
BORDEDE.setEnabled(true);
BORDEDE.setFocusable(true);
BORDEDE.setBackground(Color.red);
System.out.println(BORDEDE);
}
private void Action() {
Frame.add(BORDEDE);
}
public static void main(String[] args) {
ProbadorCodigos Ventana=new ProbadorCodigos();
Ventana.Frame.setVisible(true);
}
}
我不知道爲什麼它不顯示不透明的,如果我用一個JLabel
的作品,所以我錯過了什麼?
感謝您的建議和答案
'「,這不是一個好主意使用大量的進口,所以我不想使用JPanel或JLabel」' - 嗯?請解釋一下,因爲它確實沒有意義?另外,你的組件如何行爲不端。你如何證明它不是不透明的? – 2014-10-16 16:58:12
mmm我不想使用JPanel或JLabel,因爲他們有不需要的方法 – WearFox 2014-10-16 17:00:50
這並不能說明你不想使用JPanel的動機,而JPanel本質上是不透明的。另外,請在我上面的評論中提及我的其他問題。你怎麼知道你的JComponent其實不是不透明的?你在它的'paintComponent(...)'方法中填充圖像還是背景顏色? – 2014-10-16 17:02:08