Results 1 to 3 of 3
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default Adding JButton to JInternalFrame, grid doesnt work..

    Hey!
    Im making this SQL manager GUI software.
    Mainly for my own use, but If I succed I'll ofcourse give it out fo free :)

    Anyways, I got a problem.
    I got this jInternalFrame
    And then I do this:
    Java Code:
    JButton b = new JButton(name);
    		b.setSize(240, 20);
    		b.setVisible(true);
    		JLayeredPane c = (JLayeredPane) DB.getLayeredPane();
    		GridBagConstraints c1 = new GridBagConstraints();
    		c1.gridy = initDatabases;
    		c1.ipadx = 100;
    		c1.fill = GridBagConstraints.HORIZONTAL;
    		System.out.println(initDatabases);
    		c.add(b,c1);
    		c.validate();
    		initDatabases++;
    Simply, I create a button in this method. Then I add it to the layerdPane
    And the DB (jInternalFrame) is suppose to have GridBagLayout
    But it doesnt work because as I have added 3 buttons
    Then they should be after eachother, moving down 1 grid for each button.

    BUT that doesnt work :(
    Idk why but they all end up on same position..
    Do you know why? Please reply if you do :)

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

    Default

    From what I can tell in this small code snippet, you don't appear to be using GridBagLayout correctly, in particular the GridBagConstraints. Where are you setting the gridx, height, width, weight, etc...

    Have you gone through the GridBagLayout tutorials?

    Myself, I try to avoid using this layout unless necessary.

  3. #3
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    I was indeed :D
    Just before reading this I realised that I had done:
    JInternalFrame.setLayout(new GridBagLayout());
    But I wasnt adding them to the internalframe but to the layoutpane!!
    So I set the layoutpane on to GridBagLayout and now it works :D

    AWSOME!!
    Thanks for your time :)

Similar Threads

  1. PrintWriter doesnt work :(
    By Addez in forum New To Java
    Replies: 11
    Last Post: 01-17-2010, 06:59 PM
  2. mysql connect button doesnt work quite right
    By 711groove in forum New To Java
    Replies: 0
    Last Post: 12-13-2009, 08:01 AM
  3. Dll Call doesnt work
    By INFACT in forum New To Java
    Replies: 1
    Last Post: 10-04-2009, 10:31 PM
  4. Getting a grid with cell properties to work.
    By GAZ082 in forum AWT / Swing
    Replies: 2
    Last Post: 02-11-2009, 09:17 PM
  5. java doesnt allow vista to work
    By 10rosas in forum New To Java
    Replies: 5
    Last Post: 12-22-2008, 05:23 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
  •