2017-05-06 26 views
-1
改變圖像的JLabel

我的工作,其中m問顯示保存在數據庫(SQL)記錄的Java項目。其是一個簡單的應用程序,它顯示的網球選手的紀錄,當您選擇他/她的名字。 我面臨的問題,而把圖像的JLabel爲各自的玩家選擇。 我只是不知道如何解決這個問題。 如果可以的話,我沒有那麼多的專家如Java編碼器,所以請線性的,就像你可以請提供一個有效的解決方案。如何動態地在Java中

謝謝。

回答

0

您可以使用此代碼來顯示圖像的JLabel成。如果你想顯示動態數據到FRAM,那麼你必須創建一個JLabel JLabel label = new JLabel(imageIcon);使用id從DB獲得動態域名只母牛。

JFrame.setDefaultLookAndFeelDecorated(true); 
JFrame frame = new JFrame(); 
frame.setTitle("JLabel Test"); 
frame.setLayout(new FlowLayout()); 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

ImageIcon imageIcon = new ImageIcon("yourFile.gif"); 
JLabel label = new JLabel(imageIcon); 

frame.add(label); 
frame.pack(); 
frame.setVisible(true); 
+0

我不認爲這會奏效,因爲圖像會隨着我選擇查看其細節的玩家而改變。防爆。當我選擇Sachin時,在JLable中應該是Sachin而不是其他人。 – vinay