Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: setSize on a button ??

  1. #1
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Question setSize on a button ??

    hello,

    sorry to bother evryone but im having trouble on finding info.

    anyways im learning trough a book and im at a part where i code several buttons and make em set text in a textfield.

    the way it does it in the book is this

    add(knop1);


    knop1 = new JButton("Klik Hier");
    knop1.addActionListener(new Knop1Handler());


    class Knop1Handler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    tekstvak1.setText("Random text");

    but i cant seem to figure out how to inscrease the size of those buttons.

    i tried putting down

    knop1.setSize(100,50);

    but it doesnt seem to change, in wichever part i put the line ?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

    Default Re: setSize on a button ??

    What layout manager are you using? If you don't know, then it's time to learn about them. Do a google search of "java layout managers" for the official tutorials.

    If you're still confused after reading that, post an SSCCE and a specific question, and we'll try to help you.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: setSize on a button ??

    ah i see,

    kinda feel dumb, cant figure out what layout manager i am using.

    i didnt select one, did not make a layout or whatever i am using eclipse => start new java project => add package => add Class => put in code => run as Java Application

    i tried looking in tabs. preferences/properties and scrambling trough them but theres nothing about a layout.

    so i pressume that im using a default layout set by eclipse.

    dont know if this makes a difference i import javax.swing?
    Last edited by bjornlindekens; 06-20-2012 at 07:18 PM.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

    Default Re: setSize on a button ??

    Eclipse shouldn't have anything to do with the layout you're using, neither should your import statements. I would read through the layout manager tutorial to discover what your options are, then use a layout that sizes the button how you want it.
    bjornlindekens likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: setSize on a button ??

    i was reading ahead in the book and it states the following.

    this layout, called flowlayout is standard for a Jpanel.
    so now its telling me to shut off the layout manager bye setLayout(null);
    in the constructor of the Jpanel.

    so thats why i didnot encounter the layouts yet

    so im gonna try and figure that out instead of bothering evryone

    thnx for pointing out where to look helped alot :)

    Ps: look mommy i made my first app with buttons that actually do something!!! :D (dont judge im excited)

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

    Default Re: setSize on a button ??

    Quote Originally Posted by bjornlindekens View Post
    i was reading ahead in the book and it states the following.

    this layout, called flowlayout is standard for a Jpanel.
    so now its telling me to shut off the layout manager bye setLayout(null);
    in the constructor of the Jpanel.

    so thats why i didnot encounter the layouts yet

    so im gonna try and figure that out instead of bothering evryone

    thnx for pointing out where to look helped alot :)
    No problem. Looks like you were just getting ahead of your book. That's not a bad thing!

    Quote Originally Posted by bjornlindekens View Post
    Ps: look mommy i made my first app with buttons that actually do something!!! :D (dont judge im excited)
    Oh I would never judge that. You should see how excited I get about figuring out similar things as I'm learning css!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: setSize on a button ??

    Quote Originally Posted by bjornlindekens View Post
    i was reading ahead in the book ...

    so now its telling me to shut off the layout manager bye setLayout(null);
    in the constructor of the Jpanel.
    I really wish people who advocate doing things the lazy but wrong way could be banned from publishing garbage like that.

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

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

    Default Re: setSize on a button ??

    Quote Originally Posted by DarrylBurke View Post
    I really wish people who advocate doing things the lazy but wrong way could be banned from publishing garbage like that.

    db
    Truth. Hopefully it quickly follows it up with "but don't do this!".
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: setSize on a button ??

    i suppose it just lets you see all the different ways that are possible even tough they maybe wrong .

    its good that you mentioned it helps me in not wasting time trying to learn it this way and explore the rest.

    bad thing about a/this book seems to be going overboard on subjects that i find less relevant and rushing over topics that i want to explore more.

    if you have any reccomendations on books/tutorials etc pls do share :)

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

    Default Re: setSize on a button ??

    Quote Originally Posted by bjornlindekens View Post
    if you have any reccomendations on books/tutorials etc pls do share :)
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Japplet setSize()
    By ninjaturtlez in forum Java Applets
    Replies: 6
    Last Post: 12-22-2011, 02:32 AM
  2. setSize without frames
    By Javaer in forum New To Java
    Replies: 1
    Last Post: 01-09-2011, 03:41 AM
  3. setSize on BoxLayout
    By smray7 in forum New To Java
    Replies: 7
    Last Post: 12-16-2010, 12:18 AM
  4. setSize() not working?
    By AedonetLIRA in forum Java Applets
    Replies: 3
    Last Post: 12-02-2010, 06:17 AM
  5. When to use setSize()
    By Lil_Aziz1 in forum New To Java
    Replies: 7
    Last Post: 05-29-2010, 04:26 PM

Posting Permissions

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