2014-10-28 121 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