Link to home
Start Free TrialLog in
Avatar of nutless
nutless

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of VGR
VGR

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VGR
VGR

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 ?