generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Java help? Using JButton.

Previous Thread :: Next Thread 
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
03 May 2012 03:52 PM
So, I want to create a JButton, inside a JFrame with the size of (25,25), and at a position of (25,25): here's my code.
import javax.swing.*;
public class mainJFrame{
public static void main(String[] args){
JFrame frame = new JFrame("ROBLOX Plugin Template");
frame.setSize(400, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create a button
JButton button = new JButton();
button.setLocation(25,25);
button.setSize(0,0);
//Add the button
frame.getContentPane().add(button);
}
}

- Cheers!
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
03 May 2012 03:53 PM
Also, it create's a button the size of the whole JFrame, no matter what I set the [button.setSize(X,X);]

- Cheers!
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
03 May 2012 04:06 PM
Posts here should be about rbx.lua

inb4brandon
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
03 May 2012 04:09 PM
No...

- Cheers!
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
03 May 2012 04:14 PM
Yes...

- Cheers!
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
03 May 2012 04:16 PM
You need to change the layout style for the object. What the "size" property is actually used for depends on the layout scheme, and it isn't used at all by the default scheme.

Search "swing layouts" for more info. I don't know enough about them to give you the right one for your situation off the top of my head.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
03 May 2012 04:16 PM
Try setting it to 0.5, 0.5...
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
03 May 2012 04:52 PM
When setting the size to [(0.5,0.5)], I get NO button, and an error saying something like "I hate decimal's". :\

- Cheers!
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
03 May 2012 04:54 PM
When using GridLayout (Do I need to import it), I get an error:

cannot find symbol
  symbol: class GridLayout
  location: class mainJFrame

frame is already defined in main(java.lang.String[])

- Cheers!
Report Abuse
popinman322 is not online. popinman322
Joined: 04 Mar 2009
Total Posts: 5184
03 May 2012 05:08 PM
In order to set specific positions and sizes, you need an absolute layout.

`frame.setLayout(null);`

You can also reduce the method calls when sizing your button by using the `setBounds` method.

import javax.swing.*;
public class mainJFrame{
public static void main(String[] args){
JFrame frame = new JFrame("ROBLOX Plugin Template");
frame.setSize(400, 200);
frame.setVisible(true);
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create a button
JButton button = new JButton();
button.setBounds(25,25,25,25); // x, y, width, height
//Add the button
frame.getContentPane().add(button);
}
}
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
03 May 2012 07:55 PM
So setBounds, does Location(X,Y) and Size(X,Y)?

- Cheers!
Report Abuse
popinman322 is not online. popinman322
Joined: 04 Mar 2009
Total Posts: 5184
04 May 2012 06:02 PM
Indeed,

https://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Component.html#setBounds(int, int, int, int)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image