Results 1 to 4 of 4
  1. #1
    kratos27 is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default creating an invisible JButton

    hey all had a quick question,
    I wanted to add a jbutton to a panel but just for its physical space on the panel and not so users can see it.

    iv got the code:

    p7.add(new JButton("Im invisible"));

    i was thinking something like this:
    p7.add(new JButton("Im invisible"){Visible=false});

    but that doesnt work.

    Iv got alot of invisible buttons to add hence i am not taking the route that invloves creating and naming jbutton variables and then using method setVisible to make them invisible.

    Any ideas? Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default

    That doesn't work because that's not valid syntax at all.

    How is that an easier approach than simply calling setVisible()?

    And why are you adding invisible JButtons again? I'm pretty sure there's a better way to accomplish whatever it is you're trying to do.
    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
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by kratos27 View Post
    Any ideas? Thanks
    Have a look at the Box class; it can create invisible componenents (that take up space) for you.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    kratos27 is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    That doesn't work because that's not valid syntax at all.

    How is that an easier approach than simply calling setVisible()?

    And why are you adding invisible JButtons again? I'm pretty sure there's a better way to accomplish whatever it is you're trying to do.
    The reason why i want to add invisible buttons is because i am using a mixture of GridLayouts and BorderLayouts and with gridlayout you have to specifiy the number of rows and columns e.g. gridlayout(4,1) (means 4 rows and 1 column).

    However i want to add my button to the 4th row because of its position and so i add other invisible buttons before it, so that they will occupy the above space.

    The reason why i do not want to instantise new JButton variables is because i will not be needed the invisible buttons ever again, and so dont require them to have a local name or take up memory.

    Perhaps I should be using another layout manager?

    Quote Originally Posted by JosAH View Post
    Have a look at the Box class; it can create invisible componenents (that take up space) for you.

    kind regards,

    Jos
    Im going to have a look at this. Thanks.

Similar Threads

  1. Thread updates invisible GUI
    By matthew712 in forum Threads and Synchronization
    Replies: 4
    Last Post: 10-16-2010, 09:26 PM
  2. Creating shortcutkey for jbutton
    By vsmilejay in forum AWT / Swing
    Replies: 2
    Last Post: 09-01-2010, 01:20 PM
  3. Invisible component
    By lupo in forum AWT / Swing
    Replies: 3
    Last Post: 04-07-2010, 05:43 PM
  4. how to give JButton a name when creating GridLayout
    By yasmin k in forum AWT / Swing
    Replies: 5
    Last Post: 11-03-2009, 11:16 PM
  5. Creating a JButton that does not show focus
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-26-2008, 07:38 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
  •