Results 1 to 7 of 7
Thread: Button size doesn't work.
- 02-07-2012, 10:21 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
Button size doesn't work.
My code:
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!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"); } }
Any help?
- 02-07-2012, 10:29 PM #2
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)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-07-2012, 10:35 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
Re: Button size doesn't work.
Thanks for the links, I chose the layout null and it worked! Thanks!
- 02-07-2012, 10:40 PM #4
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-07-2012, 10:45 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
-
Re: Button size doesn't work.
- 02-11-2012, 09:38 PM #7
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
Similar Threads
-
Why doesn't this work?
By mailman in forum Java AppletsReplies: 5Last Post: 01-10-2012, 01:01 PM -
Jar doesn't work
By mad72584 in forum New To JavaReplies: 35Last Post: 08-07-2011, 05:22 PM -
Keylistenr doesn't work after pressing any button from main aplication
By darkkis in forum New To JavaReplies: 6Last Post: 12-23-2009, 09:10 AM -
Why doesn't this work?
By Corder10 in forum New To JavaReplies: 1Last Post: 07-04-2009, 10:33 PM -
How to set a stack size. -Xss doesn't work
By protonus in forum New To JavaReplies: 4Last Post: 06-27-2008, 06:59 PM


4Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks