You are on page 1of 3

class MyFrame extends javax.swing.

JFrame{

// these are the components we need.


private final JSplitPane splitPane; // split the window in top and
bottom
private final JPanel topPanel; // container panel for the top
private final JPanel bottomPanel; // container panel for the bottom
private final JScrollPane scrollPane; // makes the text scrollable
private final JTextArea textArea; // the text
private final JPanel inputPanel; // under the text a container for
all the input elements
private final JPanel inputPanel1;
private final JPanel inputPanel2;
private final JTextField textField; // a textField for the text the
user inputs
private final JButton searchInquiry; // and a "send" button
private final JButton view;
private final JButton followUp;
private final JButton newFollowup;
private final JLabel srch;

public MyFrame(){

// first, lets create the containers:


// the splitPane devides the window in two components (here: top and
bottom)
// users can then move the devider and decide how much of the top
component
// and how much of the bottom component they want to see.
splitPane = new JSplitPane();

topPanel = new JPanel(); // our top component


bottomPanel = new JPanel(); // our bottom component

// in our bottom panel we want the text area and the input components
scrollPane = new JScrollPane(); // this scrollPane is used to make
the text area scrollable
textArea = new JTextArea(); // this text area will be put inside
the scrollPane

// the input components will be put in a separate panel


inputPanel = new JPanel();
inputPanel1 = new JPanel();
inputPanel2 = new JPanel();
textField = new JTextField(); // first the input field where the
user can type his text
view = new JButton("View"); // and a button at the right, to send
the text
searchInquiry = new JButton("Search Inquiry");
newFollowup = new JButton(" New Follow up");
followUp = new JButton("Follow ups");

// now lets define the default size of our window and its layout:
setPreferredSize(new Dimension(1370, 730)); // let's open the
window with a default size of 400x400 pixels
// the contentPane is the container that holds all our components
getContentPane().setLayout(new GridLayout()); // the default
GridLayout is like a grid with 1 column and 1 row,
// we only add one element to the window itself
getContentPane().add(splitPane); // due to the
GridLayout, our splitPane will now fill the whole window

// let's configure our splitPane:


splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); // we want it
to split the window verticaly
splitPane.setDividerLocation(200); // the initial
position of the divider is 200 (our window is 400 pixels high)
splitPane.setTopComponent(topPanel); // at the top
we want our "topPanel"
splitPane.setBottomComponent(bottomPanel); // and at the
bottom we want our "bottomPanel"

// our topPanel doesn't need anymore for this example. Whatever you
want it to contain, you can add it here

topPanel.add(inputPanel1);
inputPanel1.setMaximumSize(new Dimension(Integer.MAX_VALUE, 150));
// we set the max height to 75 and the max width to (almost) unlimited
inputPanel1.setLayout(new BoxLayout(inputPanel, BoxLayout.X_AXIS));

topPanel.add(inputPanel2);
inputPanel2.setMaximumSize(new Dimension(Integer.MAX_VALUE, 150));
// we set the max height to 75 and the max width to (almost) unlimited
inputPanel2.setLayout(new BoxLayout(inputPanel, BoxLayout.X_AXIS));
srch= new JLabel("Search");
inputPanel.add(srch);

bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));

bottomPanel.setLayout(new BoxLayout(bottomPanel,
BoxLayout.Y_AXIS)); // BoxLayout.Y_AXIS will arrange the content vertically

bottomPanel.add(scrollPane); // first we add the


scrollPane to the bottomPanel, so it is at the top
scrollPane.setViewportView(textArea); // the scrollPane should
make the textArea scrollable, so we define the viewport
bottomPanel.add(inputPanel); // then we add the
inputPanel to the bottomPanel, so it under the scrollPane / textArea

// let's set the maximum size of the inputPanel, so it doesn't get


too big when the user resizes the window
inputPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 150));
// we set the max height to 75 and the max width to (almost) unlimited
inputPanel.setLayout(new BoxLayout(inputPanel,
BoxLayout.X_AXIS)); // X_Axis will arrange the content horizontally

//inputPanel.add(textField); // left will be the textField


inputPanel.add(view);
inputPanel.add(followUp);// and right the "send" button
inputPanel.add(newFollowup);
show();
pack(); // calling pack() at the end, will ensure that every layout
and size we just defined gets applied before the stuff becomes visible

}
}

You might also like