JPanel Padding in Java

后端 未结 4 1874
面向向阳花
面向向阳花 2020-11-28 06:40

I have a formatting question for my Java swing application. It should be fairly straightforward, but I am having difficulty finding any aid (Every topic seems to be regardin

相关标签:
4条回答
  • 2020-11-28 06:48

    Set an EmptyBorder around your JPanel.
    Example:

    JPanel p =new JPanel();
    p.setBorder(new EmptyBorder(10, 10, 10, 10));
    
    0 讨论(0)
  • 2020-11-28 07:00

    I will suppose your JPanel contains JTextField, for the sake of the demo.

    Those components provides JTextComponent#setMargin() method which seems to be what you're looking for.

    If you're looking for an empty border of any size around your text, well, use EmptyBorder

    0 讨论(0)
  • 2020-11-28 07:01
    JPanel p=new JPanel();  
    GridBagLayout layout=new GridBagLayout(); 
    p.setLayout(layout); 
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill=GridBagConstraints.HORIZONTAL; 
    gbc.gridx=0;   
    gbc.gridy=0;   
    p2.add("",gbc);
    
    0 讨论(0)
  • 2020-11-28 07:06

    When you need padding inside the JPanel generally you add padding with the layout manager you are using. There are cases that you can just expand the border of the JPanel.

    0 讨论(0)
提交回复
热议问题