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 regarding removing any default padding in JPanel). The text in my various JPanels hug the sides and top, touching the colored borders: how can I add padding? Thank you.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
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 theJPanel
.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
Set an
EmptyBorder
around yourJPanel
.Example: