How do I keep the frame here from blowing off of the Windows Window?
I actually WANT the scrollPane to be two of the panels (p) that are
in it high and to have the panel with the exit button in it outside
the scroll and have any panels more than two be scrolled to.
Everything grows to the point, as it is now, to where the exit button
is barely in the windows window. If I take it out of the scroll, you
can't get to it nohow.
/**
* Opens a window showing the used cards ordered by suit & value
*
*@author john sayre
*@created March 21, 2003
*/
class doUsedGui extends JFrame {
Vector Used;
//Contains all of the hands
Vector Rows = new Vector();
//will contain panels of 5 cards each
//will contain the card images
JPanel p1;
JPanel p;
//panel of 5 images
GridLayout g;
//for the panel to set up the # of rows it needs based on 5
cards per row
JPanel bp = new JPanel(new GridLayout(1, 1, 4, 4));
//Exit button goes here
/**
* Constructor for the doUsedGui object
*
*@param pUsed Cards already used, sorted by suit then value
*/
doUsedGui(Vector pUsed) {
Used = pUsed;
}
/**
* Plugs card image paths into vector of panels
*/
public void getRows() {
setTitle("Used Cards");
setMaximizedBounds(new Rectangle(5, 5));
setResizable(false);
int rows = ((int) Math.ceil(Used.size() / 5));
//as many rows as needed
int image = 0;
//get each image from the vector
System.out.println("Used size " + Used.size());
for (int panels = 0; panels < rows; panels++) {
//add panels to row vector
p = new JPanel(new GridLayout(1, 5, 4, 8));
for (int iconNo = 0; iconNo < 5; iconNo++) {
//5 icons per row
System.out.println("Row " + panels
+ " column " + iconNo);
if (image < Used.size()) {
//images < total in used card
vector
Card card = new Card();
card = (Card) Used.get
(image++);
p.add(new JLabel(new ImageIcon
(
"C:\\java\\dev\\pokerg\\Cards\\" + card.cName +
".gif")));
}
}
Rows.add(p);
//add panel to vector
}
doFrame();
//add the panels to the frame
}
/**
* creates new frame with panels of cards
*/
private void doFrame() {
JButton exitButton = new JButton(" Exit ");
bp.add(exitButton);
JPanel p2 = new JPanel();
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
p1 = (JPanel) getContentPane();
p1.setLayout(new BorderLayout());
p1.setMaximumSize(new Dimension(100, 5));
//p1 = new JPanel(new BoxLayout(p1,
BoxLayout.Y_AXIS));
exitButton.addActionListener(
new ActionListener() {
public void actionPerformed
(ActionEvent e) {
dispose();
}
});
System.out.println("Rows size " + Rows.size());
for (int i = 0; i < Rows.size(); i++) {
p2.add((JPanel) Rows.get(i));
System.out.println("
Row " + i);
}
p2.add(bp);
JScrollBar jsc = new JScrollBar();
JScrollPane jsp = new JScrollPane(p2);
jsc.setMaximum(5);
jsp.setVerticalScrollBar(new JScrollBar());
p1.add(jsp, BorderLayout.CENTER);
pack();
setVisible(true);
}
}