2014-10-28 118 views

回答

0

我不太確定如何回答你的問題,但我確實有一個想法,你可能會喜歡... 你可以試着做一個自定義標籤(使用paintComponent()或paint( )方法我建議的paintComponent())

例如:


(如果你要使用的paintComponent(),你需要把它變成一個JPanel類, 但如果你如果你選擇使用paint()方法,你需要去掉super.paintCompone nt(g)line。)

public void paintComponent(Graphics g){ 
     super.paintComponent(g); 

     //first color and first half 
     g.setColor(Color.RED); 
     g.fillRect(10, 10, 40, 40); 

     //second color and second half 
     g.setColor(Color.GREEN); 
     g.fillRect(50, 10, 40, 40); 

     //Obviously sets the text, its color, etc. 
     g.setFont(new Font("Arial", Font.BOLD, 20)); 
     g.setColor(Color.BLACK); 
     g.drawString("TEXT", 25, 36); 

} 

現在,假設你知道如何使用所有這些。你可以繼續使用它,然後製作你想要的顏色和文字。

如果您不明白某些事情,請隨時提出問題!

如果這有幫助請豎起大拇指!

+0

當然,這種做事方式會花費更多的精力和時間。要獲得「自定義標籤」,您希望它看起來如何。 – MainHeader 2014-11-03 23:37:15