Results 1 to 3 of 3
Thread: How to place panel into frame
- 11-19-2007, 06:50 AM #1
Member
- Join Date
- Nov 2007
- Posts
- 3
- Rep Power
- 0
How to place panel into frame
Hi Everybody !! I am new to Swing and am working on a GUI based Elevator Simulation System. I am using Frame on which I am trying to put a Panel. But the panel does not set to the size I want it to even if I use setSize() method. I am posting the code .Could anyone please help me.
Thanks !!
Java Code:package elevator; import javax.swing.*;import java.awt.*; public class Controller { public static void main(String args[]) { Container cpane; JFrame frame = new JFrame("ELEVATOR"); cpane = frame.getContentPane(); Lift1Panel lp1 = new Lift1Panel(); frame.setVisible(true); frame.setSize(1300,800); frame.add(lp1); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } package elevator; import javax.swing.*;import java.awt.*; public class Lift1Panel extends JPanel { public Lift1Panel() { setSize(200,200); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; g2d.setColor(Color.WHITE); g2d.drawRect(10,10,100,100); } }
- 11-19-2007, 04:29 PM #2
Java Code:import javax.swing.*; import java.awt.*; public class ControllerRx { public static void main(String[] args) { JFrame frame = new JFrame("ELEVATOR"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container cpane = frame.getContentPane(); cpane.setLayout(new GridBagLayout()); Lift1Panel lp1 = new Lift1Panel(); frame.add(lp1, new GridBagConstraints()); frame.setSize(600,400); frame.setVisible(true); } } class Lift1Panel extends JPanel { public Lift1Panel() { setPreferredSize(new Dimension(200,200)); setBackground(Color.pink); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; g2d.setColor(Color.WHITE); g2d.drawRect(10,10,100,100); } }
- 11-19-2007, 11:21 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
How can i copy a folder from one place to another..
By rajeshgubba in forum New To JavaReplies: 4Last Post: 06-14-2008, 02:21 AM -
Want Some Expert Advice? JAX India 2008 Might Be the Right Place
By james in forum Java SoftwareReplies: 2Last Post: 03-03-2008, 08:05 PM -
Help with drag from panel
By fernando in forum AWT / SwingReplies: 2Last Post: 08-07-2007, 10:19 PM -
how to place a divider of the splitpane?
By christina in forum New To JavaReplies: 1Last Post: 08-06-2007, 07:41 PM -
how to place an image in an applet
By paty in forum Java AppletsReplies: 2Last Post: 08-04-2007, 05:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks