• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

Problem getting GUI to size properly

Hi,

    I have created a JPanel to which I add a JTable and alot of JButtons.  I then instantiate this JPanel inside my main method and then add it to my JFrame.

Here a snippet of my "main method":

 public static void main(String s[]) {
    JFrame frame = new JFrame("Kirk");
    //pass handle of JFrame
    DataFileTable panel = new DataFileTable(frame);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setForeground(Color.black);
    frame.setBackground(Color.lightGray);
    frame.getContentPane().add(panel,"Center");
    frame.setSize(panel.getPreferredSize());
    frame.pack();
    frame.setVisible(true);
    frame.addWindowListener(new WindowCloser());
    }

The problem is that when I execute my program the GUI comes out "squeeze" looking. Instead of displaying seven buttons it display three buttons.  The only way for me to get the full display is to stretch out the frame.

I think the only way to fix my problem is to set a size to my panel since my frame set its size from the panel that is added.


If anyone knows a better solution please let me know.

--nutless

0
nutless
Asked:
nutless
  • 2
1 Solution
 
VGRCommented:
you may enumerate controls owned by the panel and resize accordingly by adding their width properties...
0
 
VGRCommented:
if my answer did not suit you, I prefer you refuse it rather than giving me a grade "C"
If my stupid suggestion led you to the solution, it should be B or A

Please re-read the guidelines as for what are grades "A", "B" and "C"

community support : anyone ?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now