[英]Successfully updating Look and Feel but still having errors
我試圖更新我的外觀和感覺沒有任何錯誤,但我無法弄清楚我做錯了什么。
這是我的Window類:
public class Window extends JFrame {
private static final long serialVersionUID = 1L;
public Window() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new MigLayout());
setExtendedState(JFrame.MAXIMIZED_BOTH);
setMinimumSize(new Dimension(600, 700));
setVisible(true);
setContentPane(new JPanel() {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
g.drawImage(new ImageIcon("start.jpg").getImage(), 0, 0, getWidth(),
getHeight(), this);
}
});
}
}
這是我更新UI的主要內容(外觀和感覺)
public class Main {
public static void main(String[] args) {
Window.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel(new SubstanceGraphiteLookAndFeel());
}
catch (UnsupportedLookAndFeelException e) {}
Window window = new Window();
}
}
控制台說我的錯誤來自這一行:Window window = new Window();
然后這一行:setContentPane(new JPanel(){
但是,如果我刪除整個setContentPane塊,則錯誤指向構造函數。
任何幫助,將不勝感激。 謝謝!
SubstanceGraphiteLookAndFeel()必須包裝到invokeLater()中
窗口窗口=新窗口(); shold被包裝到invokeLater()中,更多參見Oracle教程初始線程
g.drawImage(new ImageIcon(“start.jpg”)。getImage(),0,0,getWidth(),getHeight(),this);
使用BufferedImage,加載為局部變量
從API中實現的每個鼠標,鍵事件和內部方法調用paintComponent,然后非常困難和長時間ImageIcon(“start.jpg”)。getImage()被重復調用,重復調用任何事件的次數,
加載到局部變量
setContentPane(new JPanel(){,覆蓋getMin / Max / PreferredSize
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.