Java Swing help

Discussion in 'OT Technology' started by D1G1T4L, Jul 31, 2003.

  1. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    [​IMG]


    as you can see there is a big gap between Save + Cancel buttons and Birthday fields, whats a good way to eliminate it (also add a little gap between save + cancel button and bottom of the gui)

    the code i use is

    Code:
    Container mainCon = getContentPane();
    		
    		Container igCon = new Container();
    		igCon.setLayout(new FlowLayout());
    		igCon.add(mainInfo);
    		igCon.add(aInfo);
    		igCon.add(bDay);
    		JButton save = new JButton("Save");
    		save.addActionListener(this);
    		JButton cancel = new JButton("Cancel");
    Container scCon = new Container();
    		scCon.setLayout(new FlowLayout());
    		scCon.add(save);
    		scCon.add(cancel);
    
    		mainCon.add(BorderLayout.CENTER, igCon);
    		mainCon.add(BorderLayout.SOUTH, scCon);
    
    mainCon is the container that holds everything together
    igCon is container that holds all the fields, main, additional, bday
    scCon is container that holds save and cancel buttons
     
  2. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Set their positions using x and y coords.
     
  3. Black Light

    Black Light Guest

    Please tell me Java has .Top and .Left for button properties :uh:
     
  4. Black Light

    Black Light Guest

    And if u can't get buttons any closer then it's an OCX limitation of the button container. Create your own and draw it as closer as u want it to be :slap:
     
  5. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    example?

    this is not a java applet, i thought u could only use x and y coords in java applets or if u add in the applet to swing component
     
  6. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Here is a method I use in all of my apps:

    Code:
    private void addLayeredComponent(Component c, int x, int y, int w, int h, int layer)
    {
      c.setBounds(x, y, w, h);
      layeredPane.add(c, new Integer(layer));
    }
    
    I use a JLayeredPane, but you can probably still set the bounds of any control using a different layout manager.
     
  7. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    btw what GUI builders do you guys use for java except JBuilder?
     
  8. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    I always write it by hand. JBuilder's tool really sucks IMO.
     
  9. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    same here but sometimes it's annoying to run into bugs like these

    i wish java had some cool GUI designer like Visual studio for C# :wtc:
     
  10. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    You can't run to a "dumb everything down" tool when you have a bump. Take your time, ask some questions, and you'll figure it out. ;)
     
  11. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    i already had it fixed like this

    [​IMG]


    just by having FlowLayout and adding bunch of "-"

    but i am guessing it would look messed up on different resolutions and monitors heh :o
     
  12. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    As long as you fixed the size of the frame and don't allow resizing, you should be fine with that. ;)
     
  13. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    heheheh, he said properties... :rofl:
     
  14. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    [​IMG]

    fixed it


    i used igCon.add(Box.createRigidArea(new Dimension(444, 8)));

    which creates blank space (you can specify width, height) etc

    conclusion: if you want to make a GUI program, learn C#
     
  15. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Or learn Swing.
     
  16. Black Light

    Black Light Guest

    :fawk:

    I installed Visual Studio.NET last night. Time for learning VB.NET and C# :naughty:
     
  17. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Hehe, I was just kiddin. Have fun with C#. :bigthumb:
     
  18. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    swing = :greddy:
     
  19. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    If you know what you're doing, swing is very simple and effective. If you dislike swing so much, why are you using it? :confused:
     
  20. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    man it's not as hard as MFC or whatever but writing it by hand is harder than using cool RAD tools like microsoft has

    reason i am doing it is because i still want to learn it so just i can put it on my resume and if any future projects require it, i'll be able to handle them but i am prolly going to learn C# for GUI and leave java for jsp/servlets

    ;)
     
  21. Black Light

    Black Light Guest

    I might need some tutoring in C#. You gonna be on AIM tonight? :x:
     
  22. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    buy a book?
     
  23. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    I'm not qualified to give instructions on C#. :hs:

    I would suggest getting a good book and doing as many examples as you can think of. That's what I need to do more of. I just don't have the time right now. :nuts:
     

Share This Page