Im back again....
The: topCards.setLayout(new GridLayout(1, 0)); didnt make the buttons smaller...it stayed the same...
So, I tryed using a JPanel and flowlayout inside the border layout to make the buttons smaller... and it worked
But, ive run into another problem...for the card game i want three buttons at the top(north position) and three and the bottom(south position).
I wrote 3 buttons for each area, with coordinates, but only 1 button shows in each area...
I looked up BoxLayouts,GridLayouts, CardsLayouts, gridLayouts...ects
But im still confused on how to make it work...
Can someone point me towards the right direction...
OR give me example...
CODE HERE:________________________________
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Layout extends JFrame{
public static void main(String[] args) {
JFrame frame = new JFrame("UNO"); // sets JFrame to say UNO
frame.setSize(850, 400); // set width and height of frame
frame.setLocationRelativeTo(null); // center it in middle
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
LayoutManager border = new BorderLayout(1, 1); // border layout
frame.setLayout(border);
//JButton button = new JButton("TOP Cards");
//__TOp Cards________________________//
JPanel topCard1 = new JPanel(); // area for card 1
topCard1.setLayout(new FlowLayout(FlowLayout.RIGHT,620,3));
topCard1.add(new JButton(" Card1 "));
frame.add(topCard1, BorderLayout.NORTH); // should i add something here to be able to add mutiple buttons ??
JPanel topCard2 = new JPanel(); // Area for card 2
topCard2.setLayout(new FlowLayout(FlowLayout.RIGHT,340,3));
topCard2.add(new JButton(" Card2 "));
frame.add(topCard2, BorderLayout.NORTH);
JPanel topCard3 = new JPanel();
topCard3.setLayout(new FlowLayout(FlowLayout.RIGHT,220,3)); // Area for card 3
topCard3.add(new JButton(" Card3 "));
frame.add(topCard3, BorderLayout.NORTH);
//___Bottom Cards________________________________//
//JButton button2 = new JButton("Bottom Cards");
JPanel bottomCard1 = new JPanel();
bottomCard1.setLayout(new FlowLayout(FlowLayout.RIGHT,620,3)); // hgap(horizontal), vgap(vertical) used a flowlayout for button
bottomCard1.add(new JButton(" Card 1 "));
frame.add(bottomCard1, BorderLayout.SOUTH);
JPanel bottomCard2 = new JPanel();
bottomCard2.setLayout(new FlowLayout(FlowLayout.RIGHT,340,3));
//bottomCards2.setLayout(new BoxLayout(bottomCards2, BoxLayout.Y_AXIS)); // box layout
bottomCard2.add(new JButton(" Card 2 "));
frame.add(bottomCard2 ,BorderLayout.SOUTH);
JPanel bottomCard3 = new JPanel();
bottomCard3.setLayout(new FlowLayout(FlowLayout.RIGHT,220,3));
bottomCard3.add(new JButton(" Card 3 "));
frame.add(bottomCard3, BorderLayout.SOUTH);
//JPanel content = new JPanel();
//content.setLayout(new FlowLayout());
//content.add(new JButton());
//content.add(new JButton("2"));
//content.add(new JButton("This is button three"));
//content.add(new JButton("four"));
//frame.add(bottomCards, BorderLayout.SOUTH);
// for each button
frame.setVisible(true); //
}
}