I have a problem.
I have JFrame element.
Inside this frame element there's PaintingPanel (extends swing JPanel class) with layout set to FlowLayout(FlowLayout.LEFT)
and fixed width and height.
Inside PaintingPanel there's CanvasPanel element (extends JPanel class aswell).
CanvasPanel has layout set to GroupLayout (2x2). In the left top cell I have canvas element.
In other 3 cells I have resizers for canvas. Resizer extends JPanel class aswell.
When resizing canvas I want to resize CanvasPanel aswell with the (canvas) resizers. I also want the resizers to be fit the canvas dimension:
- right, horizontal resizer should have width of 10px and height of canvas
- bottom, vertical resizer should have width of canvas and height of 10px
- bottom-right, (both horizontal and vertical) resizer should be 10px by 10px
I also don't want to resize PaintingPanel.
How can I acheive desired result?
This is the code of the layout in CanvasPanel:
private void setDefaultLayout()
{
GroupLayout layout = new GroupLayout(this);
setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addComponent(canvas)
.addComponent(resizers.get("middle-right")))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(resizers.get("bottom-middle"))
.addComponent(resizers.get("bottom-right")))
);
layout.setVerticalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(canvas)
.addComponent(resizers.get("bottom-middle")))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(resizers.get("middle-right"))
.addComponent(resizers.get("bottom-right")))
);
}
This is the current method for resizing the CanvasPanel
public void resizeCanvas(int width, int height)
{
this.width = width + 40;
this.height = height + 40;
setSize(width, height);
setPreferredSize(new Dimension(this.width, this.height));
setMinimumSize(new Dimension(this.width, this.height));
setMaximumSize(new Dimension(this.width, this.height));
canvas.setSize(width, height);
}
May anyone help?