CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: setSize?

  1. #1
    Join Date
    Mar 2000
    Posts
    123

    setSize?

    I've grouped objects into JPanels with x-axis boxlayout...this works fine as I now have the controls in the locations I want. Only problems now is how to get them the size I want. setSize is not working for me. I have JLabel, JTextBox, and JButton controls.

    Example:

    private Object[] dlgObjects = new Object[2];

    private Dimension labelSize = new Dimension(50, 21);
    private Dimension textSize = new Dimension(100, 21);
    private Dimension buttonSize = new Dimension(21, 21);

    dlgObjects[0] = new JPanel();

    ((JPanel)dlgObjects[0]).setLayout(new BoxLayout (((JPanel)dlgObjects[0]), BoxLayout.X_AXIS));

    ((JPanel)dlgObjects[0]).add(flpLabel);
    ((JPanel)dlgObjects[0]).add(flpText);
    ((JPanel)dlgObjects[0]).add(flpButton);

    flpButton.setSize(buttonSize);
    flpLabel.setSize(labelSize);
    flpText.setSize(textSize);


    dlgObjects[1] = new JPanel();

    ((JPanel)dlgObjects[1]).setLayout(new BoxLayout(((JPanel)dlgObjects[1]), BoxLayout.X_AXIS));

    ((JPanel)dlgObjects[1]).add(prpLabel);
    ((JPanel)dlgObjects[1]).add(prpText);
    ((JPanel)dlgObjects[1]).add(prpButton);

    prpButton.setSize(buttonSize);
    prpLabel.setSize(labelSize);
    prpText.setSize(textSize);





  2. #2
    Join Date
    Jan 2000
    Location
    CA, USA
    Posts
    305

    Re: setSize?

    Try setBounds();

    Kannan



  3. #3
    Join Date
    Mar 2000
    Posts
    123

    Re: setSize?

    Thanks for the post, but that does not work either. I've also tried using setSize with setLocation, with and with out layout manager, and can still not size my components properly.


  4. #4
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: setSize?


    try setPreferredSize(Dimension)


  5. #5
    Join Date
    Mar 2000
    Posts
    123

    Re: setSize?

    YES! This works, it was quite apparent I was mixing my AWT components wit Swing components again (tisk, tisk) when I tried this...changed my Label to JLabel and works like a charm...much thanks.


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured