Results 1 to 8 of 8
- 05-07-2012, 05:49 PM #1
Member
- Join Date
- May 2011
- Posts
- 42
- Rep Power
- 0
Layout Vs Setbounds or setlocation problem..
well..in frames or JFrames..,,we all use setbounds and setlocation to place the components in required place in frame or JFrame,but if we resize the frame,we can observe the contents get hide...,so we use a Layout inorder to make all contents visible even after resizing..,but in Layout all placing of contents is default and we cant able to make changes using setbounds or setlocation and make to place the contents in our required position in frame or JFrame..
BECAUSE OF THIS SIMPLE ISSUE,MY MINI PROJECT GOT STOPPED IN THE MIDDLE..
so what exactly we can do if we want to place components in our required positions even by using Layout???
- 05-07-2012, 05:53 PM #2
Re: Layout Vs Setbounds or setlocation problem..
Why do you think you need to absolutely position your components?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 05-07-2012, 08:11 PM #3
Member
- Join Date
- May 2011
- Posts
- 42
- Rep Power
- 0
Re: Layout Vs Setbounds or setlocation problem..
well..just for some purposes..like...we want to places components in various parts of the frame,...as per the suggestions given to us by our project mentor...then what we need to do??
- 05-07-2012, 08:30 PM #4
Re: Layout Vs Setbounds or setlocation problem..
I highly recommend you use a layout manager. Note that you can nest layouts by putting a JPanel with one layout inside another JPanel with a different layout. A quick google of "java layout manager tutorial" will give you a link to Sun's (Oracle's) tutorial, which should be your first source of information.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 05-07-2012, 09:04 PM #5
Member
- Join Date
- May 2011
- Posts
- 42
- Rep Power
- 0
Re: Layout Vs Setbounds or setlocation problem..
well...im directly entering into the point..,here is my code....
NOW I WANT A LOGIN PAGE WHERE heading "WELCOME TO LMS" SHOULD BE ON TOP CENTER AND USERNAME AND BELOW IT PASSWORD AND BELOW IT OK BUTTON..SO WHAT CHANGES I NEED TO DO INJava Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; class lms extends JFrame implements ActionListener{ static JFrame frm; JPanel pan; JTextField name,pswd; JLabel lbl1,lbl2,lbl3,lbl4,lbl5; JButton b1; GridLayout g; public lms(){ frm=new JFrame("LMS"); pan=new JPanel(); frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frm.getContentPane().add(pan); pan.setLayout(new GridLayout(4,3,20,50)); lbl1=new JLabel("Name : "); lbl2=new JLabel("Password : "); lbl3=new JLabel("Welcome To LMS"); lbl4=new JLabel(); name=new JTextField(2); pswd=new JTextField(2); //pswd.setEchoChar('*'); b1=new JButton("OK"); name.setBackground(Color.pink); name.setForeground(Color.blue); Font f=new Font("Arial",Font.BOLD,15); Font z=new Font("Arial",Font.ITALIC+Font.BOLD,15); name.setFont(f); lbl1.setFont(f); lbl2.setFont(f); lbl3.setFont(z); lbl4.setFont(f); lbl4.setForeground(Color.RED); pswd.setFont(f); b1.setFont(f); lbl1.setBounds(50,200,20,20); lbl2.setBounds(50,250,20,20); lbl3.setBounds(50,80,20,20); lbl4.setBounds(100,350,20,20); name.setBounds(80,100,20,25); pswd.setBounds(80,100,20,25); b1.setFont(f); b1.setBounds(200,300,50,30); b1.addActionListener(this); pan.add(lbl3); pan.add(lbl1); pan.add(name); pan.add(lbl2); pan.add(pswd); pan.add(b1); pan.add(lbl4); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } public void actionPerformed(ActionEvent ae){ String s1=name.getText(); String s2=pswd.getText(); if(ae.getSource()==b1 && s1.isEmpty() && s2.isEmpty()) { lbl4.setText("Please Enter Username and Password!!!"); } else if(s1.equals(s2)){ GetFrame2 f2=new GetFrame2(); f2.setSize(500,500); f2.setVisible(true); setVisible(false);} else { lbl4.setText("Enter Correct Username and password!!!"); } } public static void main(String args[]){ lms l1=new lms(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frm.setSize(screenSize.width, screenSize.height); frm.setVisible(true); } }PLEASE TELL ME...pan.setLayout(new GridLayout(4,3,20,50));
- 05-07-2012, 09:21 PM #6
Re: Layout Vs Setbounds or setlocation problem..
Do you have a problem with your Shift and/or Caps Lock key?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
-
Re: Layout Vs Setbounds or setlocation problem..
Please don't shout, we can read you much better if you avoid all-caps. As for changes, I recommend you have a look at the layout tutorial as it will give pictorial examples of the different layouts, and then that you use this information to experiment and try out different combinations of layouts. Working this way, you'll likely both find a good combination of layouts and gain a much better understanding of the different layout managers than you would if we told you to do "this, this, and this". Also, if you do this, and get stuck, come back with your latest code and any *specific* questions, and we'll be glad to try to help you out.
- 05-08-2012, 06:47 PM #8
Member
- Join Date
- May 2011
- Posts
- 42
- Rep Power
- 0
Similar Threads
-
jlabels don't size by using setbounds within a null layout
By such orb in forum AWT / SwingReplies: 1Last Post: 03-18-2012, 12:00 PM -
GUI Problem with setBounds();
By JohnPringle83 in forum New To JavaReplies: 2Last Post: 05-17-2011, 07:18 AM -
control setLocation setBounds
By xna in forum New To JavaReplies: 3Last Post: 11-11-2009, 04:29 AM -
setLocation on a JDialog is ignored
By ScottVal in forum AWT / SwingReplies: 7Last Post: 01-13-2009, 07:35 AM -
Problem here guys: Set location or setBounds
By themburu in forum New To JavaReplies: 3Last Post: 06-03-2008, 07:19 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks