Hi there, I want to have a GUI with two panels: northPanel and southPanel. And I want the northPanle to be a GridBagLayout. But, I don't know how to add the components to it; only when it's the Frame itself that is set to GridBagLayout. Anyone has any similar example? Thanks
Hi, Just create a JPanel "northPanel", call northPanel.setLayout(new GridBagLayout()); and then call northPanel.add(new Whatever()) using a GridBagConstraints object as needed. When you're done, you can just use myFrame.getContentPane().add(northPanel, BorderLayout.NORTH); Does this answer your question? [ September 01, 2003: Message edited by: Ernest Friedman-Hill ]
OK, I think I understood you now. I changed the private void addComponent(....) to private Component addComponent( ... ) and then northFrame.add(addComponent( browseButton, 0,0,1,1 )) ; Thanks!
Your addComponent() method implicitly calls add() on (what I imagine is) your JFrame object -- i.e., an object of the class that all this code is defined in. You could change addComponent() to take another argument, the container to add the component to; then instead of calling just add(), you'd call container.add() -- i.e.,
Originally posted by Ernest Friedman-Hill: Your addComponent() method implicitly calls add() on (what I imagine is) your JFrame object -- i.e., an object of the class that all this code is defined in. You could change addComponent() to take another argument, the container to add the component to; then instead of calling just add(), you'd call container.add() -- i.e.,
Thanks a lot, much better than my solution
I want my playground back. Here, I'll give you this tiny ad for it:
Gift giving made easy with the permaculture playing cards