creating a Three 3x3 windows in java

Status
Not open for further replies.

TCD

Ars Tribunus Angusticlavius
8,220
alright, I can create 3x3 windows but they appear all scnruched up and stuff... so when I added them to a box layout all I get is a column of like

1
2
3
.
9

10
12
.
.
18

19
20
.
.
.
27

Thanks


Code:
//import the classes related to swing and awt GUI's
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.BorderFactory; 
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;


//MyFrame extends JFrame, which is the class for top level windows
// in Swing. Thus any instance of this class will be a window.
class MyFrame extends JFrame {
    public MyFrame() {
	
      Border loweredbevel;
      loweredbevel = BorderFactory.createLoweredBevelBorder();
	TitledBorder title1, title2, title3;
        setTitle("lab9");
     
	setSize(400,900);

	Container contentPane = getContentPane();
	
	JPanel gridPane1 = new JPanel();
	JPanel gridPane2 = new JPanel();
	JPanel gridPane3 = new JPanel();
	
	//gridPane1.setLayout(new GridLayout(0,3));
	//gridPane2.setLayout(new GridLayout(0,3));
	//gridPane3.setLayout(new GridLayout(0,3));

	title2 = BorderFactory.createTitledBorder(loweredbevel, "middle");
	title2.setTitlePosition(TitledBorder.ABOVE_TOP);
	gridPane2.setBorder(title2);

	title1 = BorderFactory.createTitledBorder(loweredbevel, "top");
	title1.setTitlePosition(TitledBorder.ABOVE_TOP);
	gridPane1.setBorder(title1);
	
	title3 = BorderFactory.createTitledBorder(loweredbevel, "bottom");
	title3.setTitlePosition(TitledBorder.ABOVE_TOP);
	gridPane3.setBorder(title3);


       
	gridPane1.setLayout(new BoxLayout(gridPane1, BoxLayout.Y_AXIS));
	
	gridPane2.setLayout(new BoxLayout(gridPane2, BoxLayout.Y_AXIS));
	gridPane3.setLayout(new BoxLayout(gridPane3, BoxLayout.Y_AXIS));
	//JTextField resp= new JTextField(30);
       ButtonListener pushButton = new ButtonListener();
	for(int i = 1; i < 10; i++) {
	    JButton b1 =new JButton(""+i);
           b1.addActionListener(pushButton);
	gridPane1.add(b1);
          }

	for(int i = 10; i < 19; i++) {
	    JButton b2 =new JButton(""+i);
           b2.addActionListener(pushButton);
	gridPane2.add(b2);
          }
       
	for(int i = 19; i < 28; i++) {
	    JButton b3 =new JButton(""+i);
           b3.addActionListener(pushButton);
	gridPane3.add(b3);
          }
	
	// JButton b4 = new JButton("Clear");
	//   b4.addActionListener(pushButton);
	//  gridPane.add(b4);
   
       addWindowListener(new Listener());
	
	contentPane.add(gridPane1, BorderLayout.NORTH);
	contentPane.add(gridPane2, BorderLayout.CENTER);
	contentPane.add(gridPane3, BorderLayout.SOUTH);
    }
 

Pika

Seniorius Lurkius
21
Maybe you could provided more information about what it is that you are trying to achieve as
alright, I can create 3x3 windows but they appear all scnruched up and stuff... so when I added them to a box layout all I get is a column of like

is not making a lot of sense to me. If I could have more info so that I could picture what it is that you are trying to display I might be able to help. Maybe a diagram of what the end result should look like.
 
Status
Not open for further replies.