Results 1 to 7 of 7
Thread: Layout Question
- 01-18-2010, 04:48 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
- 01-18-2010, 04:58 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
If you set a grid layout in a panel, you can add that panel to another panel that has a grid layout, effectively nesting them.
- 01-19-2010, 01:34 PM #3
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
Thanks for the reply & sorry for my late reply. i did the code but i found that there is something wrong with my code. i could compile but the gui does not appear. can someone help me see what is wrong with my code & direct me please. the error happens on jp3.add(jlProcess);. Thanks in advance.
/**
* @(#)CpuGenerate.java
*
*
* @author
* @version 1.00 2010/1/13
*/
import javax.swing.*;
import java.awt.*;
public class CpuGenerate extends JFrame{
JButton jbBack, jbReset, jbGenerate, jbNext;
JLabel jlProcess, jlArrival, jlPriority, jlBurst, jl1, jl2, jl3;
JSpinner jsProcess, jsArrival1, jsArrival2, jsPriority1, jsPriority2, jsBurst1, jsBurst2;
JCheckBox jcbEnable;
JPanel jp1, jp2, jp3, jp4, jp5, jp6;
public CpuGenerate() {
setSize(800,600);
setTitle("CPU Scheduling");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
//initialize panels
jp1= new JPanel();
jp2= new JPanel();
jp3= new JPanel();
jp4= new JPanel();
jp5= new JPanel();
jp6= new JPanel();
//set panel layout
jp1.setLayout(new GridLayout(1,2));
jp2.setLayout(new GridLayout(3,1));
jp3.setLayout(new GridLayout(1,2));
jp4.setLayout(new GridLayout(4,4));
jp5.setLayout(new GridLayout(1,3));
jp6.setLayout(new FlowLayout());
//add panels to frame
add(jp1, BorderLayout.CENTER);
/* add(jp2, BorderLayout.NORTH);
add(jp3, BorderLayout.WEST);
add(jp4, BorderLayout.SOUTH);
add(jp5, BorderLayout.EAST);*/
jp1.add(jp2);
jp1.add(jp6);
jp2.add(jp3);
jp2.add(jp4);
jp2.add(jp5);
//add components into panel
jp3.add(jlProcess);
jp3.add(jsProcess);
jp4.add(jlArrival);
jp4.add(jsArrival1);
jp4.add(jl1);
jp4.add(jsArrival2);
jp4.add(jlPriority);
jp4.add(jsPriority1);
jp4.add(jl2);
jp4.add(jsPriority2);
jp4.add(jcbEnable);
jp4.add(jlBurst);
jp4.add(jsBurst1);
jp4.add(jl3);
jp4.add(jsBurst2);
jp5.add(jbBack);
jp5.add(jbReset);
jp5.add(jbNext);
jp6.add(jbNext);
// Create spinner
JSpinner jsProcess = new JSpinner();
JSpinner jsArrival1 = new JSpinner();
JSpinner jsArrival2 = new JSpinner();
JSpinner jsPriority1 = new JSpinner();
JSpinner jsPriority2 = new JSpinner();
JSpinner jsBurst1 = new JSpinner();
JSpinner jsBurst2 = new JSpinner();
//Create Buttons
jbBack = new JButton("Back");
jbReset = new JButton("Reset");
jbGenerate = new JButton("Generate");
jbNext = new JButton("Next");
//Create label
jlProcess = new JLabel("No. Of Process:");
jlArrival = new JLabel("Arrival Time:");
jlPriority = new JLabel("Priority:");
jlBurst = new JLabel("Burst Time:");
jl1 = new JLabel("To");
jl2 = new JLabel("To");
jl3 = new JLabel("To");
//create combobox
jcbEnable = new JCheckBox("Enable");
// Set spinner value
jsProcess.setValue(new Integer(1));
jsArrival1.setValue(new Integer(1));
jsArrival2.setValue(new Integer(2));
jsPriority1.setValue(new Integer(1));
jsPriority2.setValue(new Integer(2));
jsBurst1.setValue(new Integer(1));
jsBurst2.setValue(new Integer(2));
setVisible(true);
}
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
CpuGenerate frame = new CpuGenerate();
}
}
- 01-19-2010, 01:57 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
1.) Use code tags when posting code
2.) Did you check the console for error messages/exceptions? You should be getting a Nullpointer on jp3.add(jlProcess); because jlProcess will be null at that point.
- 01-19-2010, 02:02 PM #5
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
Hi, sorry im quite new here. so i didnt know that im suppose to use code tags when posting my codes.
im quite confused about the checking console for error messages. Do you mind explaining about the nullpointer?
the error i gt was
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1041)
at java.awt.Container.add(Container.java:365)
at CpuGenerate.<init>(CpuGenerate.java:59)
at CpuGenerate.main(CpuGenerate.java:128)
- 01-19-2010, 02:08 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
- 01-19-2010, 02:11 PM #7
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
Edit layout Layout please help me
By manhtungtnk28@gmail.com in forum New To JavaReplies: 4Last Post: 11-23-2009, 08:41 AM -
Card Layout
By Gilbee in forum NetBeansReplies: 3Last Post: 03-03-2009, 09:37 PM -
Border Layout
By mark-mlt in forum Java AppletsReplies: 5Last Post: 05-12-2008, 09:48 AM -
JGraph Layout Pro 1.4.0.3
By levent in forum Java SoftwareReplies: 0Last Post: 07-31-2007, 06:43 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks