Is there way to use more than 1 layout manager in Java. Right now I'm using a gridLayout to implement a chess board but beneath it I would like to put some other stuff but not in a gridLayout. Maybe a FlowLayout or some other layout. How would I go about doing this? Thanks!
相关问题
- 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
Yes, all you need is to plan your over all UI Layout (i.e; Window, master panel etc)
For example, you need to put something under your chessboard, I would normally go with a BorderLayout at the basic level.
So assume I have a JPanel called masterPanel, that holds all the components for my chess app. So, code would look like:
Absolutely. In fact, using multiple layout managers is the norm.
Any
Container
subclass can have aLayoutManager
and contain child elements. And each of these child elements can itself be aContainer
with children. The most commonly used container below the top-level frames isJPanel
.For your example, you should probably use a
BorderLayout
for the frame, put aJPanel
with the grid in its CENTER position (because that's the one that gets all available remaining space when the other positions have been given their preferred sizes) and anotherJPanel
with the "other stuff" in the SOUTH position.More details can be found in the Swing tutorial on layout managers.