I have been playing with DesignGridLayout as a layout manager. For the most part it works rather well. However, I have an issue in this sample class:
import net.java.dev.designgridlayout.DesignGridLayout;
import javax.swing.*;
import java.awt.*;
public class ConsolePanel extends JPanel {
private ConButton oneCon = new ConButton(">");
private ConButton twoCon = new ConButton(">");
private ConButton threeCon = new ConButton(">");
private ConButton fourCon = new ConButton("<");
private ConButton fiveCon = new ConButton("<");
private ConButton sixCon = new ConButton("<");
private JTextArea console = new JTextArea(10,20);
private Dimension dim = new Dimension(430,250);
private DesignGridLayout layout = new DesignGridLayout(this);
public ConsolePanel () {
buildConsole();
}
private void buildConsole () {
layout.row().grid().add(oneCon).add(console,3).add(fourCon);
layout.row().grid().add(twoCon).spanRow().add(fiveCon);
layout.row().grid().add(threeCon).spanRow().add(sixCon);
console.setBackground(Color.BLACK);
console.setForeground(Color.GREEN);
console.setColumns(20);
console.setRows(10);
console.setLineWrap(true);
console.setWrapStyleWord(true);
console.setEditable(false);
}
@Override
public Dimension getPreferredSize() {
// comply to contract if set
if(isPreferredSizeSet())
return super.getPreferredSize();
// do whatever we want
return new Dimension(dim);
}
public JPanel getConsoleLayout() {
return this;
}
private class ConButton extends JButton {
private Dimension dim = new Dimension(10,25);
public ConButton (String text) {
super(text);
}
@Override
public Dimension getPreferredSize() {
// comply to contract if set
if(isPreferredSizeSet())
return super.getPreferredSize();
// do whatever we want
return new Dimension(dim);
}
}
}
I need to be able to resize the "<" and ">" to some smaller size. Then what the layout manager defaults to. I have tried to override the getPreferredSize()
method as noted here #21052894. Though, this isn't work quite right.
Also, this is a second JPanel inside of a JFrame/JPanel such as
--------------------------------------------- <-- JPanel inside of a JFrame | | | JPanel2 | JPanel3 | | | one I can't get | | | right |
And the JFrame/JPanel is setup as follows:
_frame = new JFrame();
_frame.setName(getClass().getSimpleName());
_frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Font titleFont = new Font(title.getFont().getName(), title.getFont().getStyle(), 16);
title.setFont(titleFont);
JPanel top = new JPanel();
top.setName("TOP");
top.setLayout(new BorderLayout());
top.add(title,BorderLayout.PAGE_START);
top.add(<Panel2>, BorderLayout.LINE_START);
top.add(<Panel3>, BorderLayout.LINE_END);
addTopPanel(top);
prePack();
_frame.pack();
_frame.setLocationRelativeTo(null);
_frame.setResizable(false);
_frame.setVisible(true);