BigV
02-26-04, 12:15 PM
Hi All
I have managed to create a scrollable list of buttons by placing the buttons in a JPanel and place the JPanel in a JScrollWindow.
I then have a GridBagLayout with the ScrollWindow at the top and Various Buttons underneath. Unfortunatley, as I insert more buttons in the JPanel, it expands over the top of the buttons at the bottom of the GridBagLayout pane.
Here is the code......
public class events extends Applet implements ActionListener, ItemListener
{
Button changeBtn, changeBtn1, changeBtn2, clearBtn; //Change and clear buttons
Label titleLabel, status, instructionLabel, resultLabel; //Label variables
TextArea originalTa, resultTa; //TextArea variables
Checkbox italicCb, boldCb; //Italic and bold checkboxes
ScrollPane arse;
void buildConstraints (GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) {
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
}
public void init()
{
//Assign RGB colors to the foreground and background
Color color = new Color(150, 150, 150);
Color fColor = new Color(0, 0, 0);
Color red = new Color(255, 0, 0);
Color green = new Color(0, 255, 0);
setBackground(color);
setForeground(fColor);
titleLabel = new Label("Java Event List", Label.CENTER);
//titleLabel.setFont(new Font("Arial", Font.BOLD, 20));
status = new Label("Set the Severiity here", Label.CENTER);
//status.setFont(new Font("Monospaced", Font.PLAIN, 11));
instructionLabel = new Label(" Please enter your text message:", Label.LEFT);
//instructionLabel.setFont(new Font("Serif", Font.BOLD, 15));
resultLabel = new Label(" Here is your new font version:", Label.LEFT);
//resultLabel.setFont(new Font("Serif", Font.BOLD, 15));
//Create No Change and Clear All buttons
changeBtn = new Button("Button 0");
changeBtn1 = new Button("Button 1");
changeBtn2 = new Button("Button 2");
clearBtn = new Button("Clear All");
//Create Italic and Bold check boxes
italicCb = new Checkbox("Italic");
boldCb = new Checkbox("Bold");
setLayout(new BorderLayout());
//Create Panel top to hold the title, instruction, and editable text area
JPanel top = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
top.setLayout(gridbag);
Panel insideScroll = new Panel();
BoxLayout box = new BoxLayout(insideScroll, BoxLayout.PAGE_AXIS);
insideScroll.setLayout(box);
for(int i=0; i<20; i++)
{
//Label myLabel = new Label("arse");
insideScroll.add(new Button("This a very long button "));
}
buildConstraints(constraints, 0, 0, 3, 1, 0, 0);
JScrollPane scrollWindow = new JScrollPane(insideScroll);
Dimension pref = new Dimension(850,350);
scrollWindow.setPreferredSize(pref);
gridbag.setConstraints(scrollWindow,constraints);
top.add(scrollWindow, constraints);
constraints.fill = GridBagConstraints.NONE;
buildConstraints(constraints, 0, 1, 3, 1, 100, 100);
JLabel label1 = new JLabel(" ");
top.add(label1, constraints);
gridbag.setConstraints(label1,constraints);
buildConstraints(constraints, 0, 2, 3, 1, 100, 100);
JLabel label2 = new JLabel("Please select the events you would like to see");
gridbag.setConstraints(label2,constraints);
top.add(label2, constraints);
//Spacer
buildConstraints(constraints, 0, 3, 3, 1, 100, 100);
JLabel label3 = new JLabel(" ");
gridbag.setConstraints(label3,constraints);
top.add(label3, constraints);
buildConstraints(constraints, 0, 4, 1, 1, 100, 100);
JButton button1 = new JButton("Critical Events");
gridbag.setConstraints(button1,constraints);
top.add(button1, constraints);
buildConstraints(constraints, 1, 4, 1, 1, 100, 100);
JButton button2 = new JButton("Clear Events");
gridbag.setConstraints(button2,constraints);
top.add(button2, constraints);
buildConstraints(constraints, 2, 4, 1, 1, 100, 100);
JButton button3 = new JButton("All Events");
gridbag.setConstraints(button3,constraints);
top.add(button3, constraints);
/*Panel insideScroll = new Panel();
BoxLayout box = new BoxLayout(insideScroll, BoxLayout.PAGE_AXIS);
insideScroll.setLayout(box);
scrollWindow.add(insideScroll);*/
add(top, "Center"); //Add Panel top to the BorderLayout
scrollWindow.requestFocus(); //For the focus in the original text area
setVisible(true);
} //End of init
Any ideas where I'm going wrong!?
bigV
I have managed to create a scrollable list of buttons by placing the buttons in a JPanel and place the JPanel in a JScrollWindow.
I then have a GridBagLayout with the ScrollWindow at the top and Various Buttons underneath. Unfortunatley, as I insert more buttons in the JPanel, it expands over the top of the buttons at the bottom of the GridBagLayout pane.
Here is the code......
public class events extends Applet implements ActionListener, ItemListener
{
Button changeBtn, changeBtn1, changeBtn2, clearBtn; //Change and clear buttons
Label titleLabel, status, instructionLabel, resultLabel; //Label variables
TextArea originalTa, resultTa; //TextArea variables
Checkbox italicCb, boldCb; //Italic and bold checkboxes
ScrollPane arse;
void buildConstraints (GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) {
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
}
public void init()
{
//Assign RGB colors to the foreground and background
Color color = new Color(150, 150, 150);
Color fColor = new Color(0, 0, 0);
Color red = new Color(255, 0, 0);
Color green = new Color(0, 255, 0);
setBackground(color);
setForeground(fColor);
titleLabel = new Label("Java Event List", Label.CENTER);
//titleLabel.setFont(new Font("Arial", Font.BOLD, 20));
status = new Label("Set the Severiity here", Label.CENTER);
//status.setFont(new Font("Monospaced", Font.PLAIN, 11));
instructionLabel = new Label(" Please enter your text message:", Label.LEFT);
//instructionLabel.setFont(new Font("Serif", Font.BOLD, 15));
resultLabel = new Label(" Here is your new font version:", Label.LEFT);
//resultLabel.setFont(new Font("Serif", Font.BOLD, 15));
//Create No Change and Clear All buttons
changeBtn = new Button("Button 0");
changeBtn1 = new Button("Button 1");
changeBtn2 = new Button("Button 2");
clearBtn = new Button("Clear All");
//Create Italic and Bold check boxes
italicCb = new Checkbox("Italic");
boldCb = new Checkbox("Bold");
setLayout(new BorderLayout());
//Create Panel top to hold the title, instruction, and editable text area
JPanel top = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
top.setLayout(gridbag);
Panel insideScroll = new Panel();
BoxLayout box = new BoxLayout(insideScroll, BoxLayout.PAGE_AXIS);
insideScroll.setLayout(box);
for(int i=0; i<20; i++)
{
//Label myLabel = new Label("arse");
insideScroll.add(new Button("This a very long button "));
}
buildConstraints(constraints, 0, 0, 3, 1, 0, 0);
JScrollPane scrollWindow = new JScrollPane(insideScroll);
Dimension pref = new Dimension(850,350);
scrollWindow.setPreferredSize(pref);
gridbag.setConstraints(scrollWindow,constraints);
top.add(scrollWindow, constraints);
constraints.fill = GridBagConstraints.NONE;
buildConstraints(constraints, 0, 1, 3, 1, 100, 100);
JLabel label1 = new JLabel(" ");
top.add(label1, constraints);
gridbag.setConstraints(label1,constraints);
buildConstraints(constraints, 0, 2, 3, 1, 100, 100);
JLabel label2 = new JLabel("Please select the events you would like to see");
gridbag.setConstraints(label2,constraints);
top.add(label2, constraints);
//Spacer
buildConstraints(constraints, 0, 3, 3, 1, 100, 100);
JLabel label3 = new JLabel(" ");
gridbag.setConstraints(label3,constraints);
top.add(label3, constraints);
buildConstraints(constraints, 0, 4, 1, 1, 100, 100);
JButton button1 = new JButton("Critical Events");
gridbag.setConstraints(button1,constraints);
top.add(button1, constraints);
buildConstraints(constraints, 1, 4, 1, 1, 100, 100);
JButton button2 = new JButton("Clear Events");
gridbag.setConstraints(button2,constraints);
top.add(button2, constraints);
buildConstraints(constraints, 2, 4, 1, 1, 100, 100);
JButton button3 = new JButton("All Events");
gridbag.setConstraints(button3,constraints);
top.add(button3, constraints);
/*Panel insideScroll = new Panel();
BoxLayout box = new BoxLayout(insideScroll, BoxLayout.PAGE_AXIS);
insideScroll.setLayout(box);
scrollWindow.add(insideScroll);*/
add(top, "Center"); //Add Panel top to the BorderLayout
scrollWindow.requestFocus(); //For the focus in the original text area
setVisible(true);
} //End of init
Any ideas where I'm going wrong!?
bigV