Is there an equivalent in Java for fieldset (HTML)?

前端 未结 3 1354
生来不讨喜
生来不讨喜 2021-02-13 04:30

Is there an element in Java (i.e. Swing/AWT or SWT) that is equivalent to the HTML element fieldset?

相关标签:
3条回答
  • 2021-02-13 05:03

    Have a look at javax.swing.border.TitledBorder. You can set them on panels and are similar in appearance to HTML fieldsets.

    Border titleBorder = new TitledBorder(new LineBorder(Color.RED), "Fieldset");
    

    You could then add the border to your panel using the setBorder() method.

    0 讨论(0)
  • 2021-02-13 05:21

    If you are using SWT than I think that org.eclipse.swt.widgets.Group is what you are looking for. It is a Composite (a block in HTML analogy) and it looks like a fieldset in HTML.

    I can't speak for AWT and SWING however.

    0 讨论(0)
  • 2021-02-13 05:25

    Create a Panel, create a titled border and you will be able to put inside all your field components.

    JPanel panel = new JPanel();
    panel.add(new JLabel("foo"));
    panel.setBorder(BorderFactory.createTitledBorder("bar")); 
    
    0 讨论(0)
提交回复
热议问题