绘制圆,子类JPanel和覆盖paintComponent:
public class CirclePanel extends JPanel {
@Override
protected void paintComponent(Graphics g) {
g.drawOval(0, 0, g.getClipBounds().width, g.getClipBounds().height);
}
}
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
替代文字http://img246.imageshack.us/img246/3708/so2343233.png
要放置标签,您可以使用GridBagLayout,希望这是您想要的:
CirclePanel panel = new CirclePanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints gc;
gc = new GridBagConstraints();
gc.gridy = 0;
panel.add(new JLabel("Label 1"), gc);
gc = new GridBagConstraints();
gc.gridy = 1;
panel.add(new JLabel("Label 2"), gc);
Run Code Online (Sandbox Code Playgroud)
替代文字http://img694.imageshack.us/img694/4013/so23432332.png
| 归档时间: |
|
| 查看次数: |
5723 次 |
| 最近记录: |