开发者

How to make a JLabel looks like a tab header of JTabbedPane

Providing the text of the JLabel is "Text",

I want a JLabel object looks like this in Nimbus:

How to make a JLabel looks like a tab header of JTabbedPane

like this in Metal:

How to make a JLabel looks like a tab header of JTabbedPane

i.e. the same as a tab header of a JTabbedPane. Is it pos开发者_Go百科sible?

Thanks.


Absolutely Yes. But not that easy.

Every Swing Component has a UI associated with it, that can be overridden by your own custom UI. You can create a JLabelUI (UI delegate class) and set it yourself, or you could simply override the paint() method of the JLabel (creating your own custom JLabel.

The next step is then to get the source of the UI that you want to copy, and take the paint function from that UI and copy it into your overridden paint method (or UI delegate class).


Maybe another solution's logic is more easy;

put JLabel into a JPanel. set JPanel's background as you wish (image, drawing with graphics etc.) and setText to JLabel. Create a widget with them and use it ;)

Note: I think @Codemwnci 's method is more acceptable ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜