Results 1 to 7 of 7
Like Tree4Likes
  • 2 Post By DarrylBurke
  • 2 Post By Fubarable

Thread: Button size doesn't work.

  1. #1
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Button size doesn't work.

    My code:
    Java Code:
    package org.tests.Test1;
    
    import javax.swing.*;
    //import java.awt.*; 
    import java.awt.Dimension;
    import java.awt.event.*;
    
    public class Test extends JFrame implements ActionListener{
    	
    	public Test(){
    		setDefaultLookAndFeelDecorated(true);
    		setSize(600,400);
    		setTitle("Admin Controls");
    		JButton startButton = new JButton("Start");
    		startButton.setPreferredSize(new Dimension(40,40));
    		startButton.addActionListener(this);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setVisible(true);
    		add(startButton);
    	}
    	
    	public static void main(String args[]) {
    		String password;
    		password = JOptionPane.showInputDialog(null, "Password: ","Admin Conrol",JOptionPane.PLAIN_MESSAGE);
    		if (password.equals("hi")) {
    			new Test();
    		} else {
    			JOptionPane.showMessageDialog(null, "Wrong Password", "ERROR", JOptionPane.ERROR_MESSAGE);
    		}
    	}
    
    	public void actionPerformed(ActionEvent e) {
    		System.out.print("Hi");
    	}
    	
    
    }
    I'm a noob in Java so bare with me if there is any noobish mistakes, everytime I load up the frame, the button fills the whole screen!
    Any help?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: Button size doesn't work.

    Go through Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing) The default layout for a JFrame's contentPane is a BorderLayout.

    Heck, go through the whole shebang or you're forever going to be asking here. Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: Button size doesn't work.

    Thanks for the links, I chose the layout null and it worked! Thanks!

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: Button size doesn't work.

    That's a very bad approach. You may get away with it for a layout with just a few components, run on only one computer, but it's better that you learn to use layouts effectively sooner rather than later.

    db
    Fubarable and camickr like this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: Button size doesn't work.

    Quote Originally Posted by DarrylBurke View Post
    That's a very bad approach. You may get away with it for a layout with just a few components, run on only one computer, but it's better that you learn to use layouts effectively sooner rather than later.

    db
    Thanks! I guess as I am a noob i'll stick with that but I might move on one day.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Button size doesn't work.

    Quote Originally Posted by rokit boy View Post
    Thanks! I guess as I am a noob i'll stick with that but I might move on one day.
    If you're smart, then you'll move on sooner rather than "one day".
    camickr and DarrylBurke like this.

  7. #7
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: Button size doesn't work.

    Quote Originally Posted by Fubarable View Post
    If you're smart, then you'll move on sooner rather than "one day".
    I'm not smart :P
    I do know lua, Batch, C++ and python plus learning Java, but I guess the three apart from C++ and Java are pretty much useless.

Similar Threads

  1. Why doesn't this work?
    By mailman in forum Java Applets
    Replies: 5
    Last Post: 01-10-2012, 02:01 PM
  2. Jar doesn't work
    By mad72584 in forum New To Java
    Replies: 35
    Last Post: 08-07-2011, 06:22 PM
  3. Replies: 6
    Last Post: 12-23-2009, 10:10 AM
  4. Why doesn't this work?
    By Corder10 in forum New To Java
    Replies: 1
    Last Post: 07-04-2009, 11:33 PM
  5. How to set a stack size. -Xss doesn't work
    By protonus in forum New To Java
    Replies: 4
    Last Post: 06-27-2008, 07:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •