maximize components when click maximize button in jframe
I have serveral jpanels in a single jframe.
jpanls contain jtree, combobox, labels, textarea etc...
I would like to maximize all the components in jpanels to fit into the jframe when i click the maximize button in the jframe. how can it be done? i would appreciate anyone who answers my questions.
zHuZhu
[338 byte] By [
zHuZhua] at [2007-11-27 11:03:53]

It all depends on the layout manager you're using.
BorderLayout for one fills the area available to it.
dwga at 2007-7-29 12:53:57 >

thank you sooooo much for your reply
but i think i didnt explain clearly enough.
i have a frame which contains a panel (named A), panel A contains serveral panels
so when i run the program, user will only see a rectangle which contains some components.
ps. i tried to add BorderLayout in the frame. but when i click on the maximize window, the screen did maximize but the rectangle remains and it's shifted to the centre of the screen.
Create a panel and set its layout to GridLayout having single cell. Add your panel into this panel. now add the grid panel to your jframe.
Hope this works.
i'm very sorry. i just tried to add another panel with gridlayout. it doesn't solve the problem too. T_T
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class TestFrame extends JFrame
{
public TestFrame()
{
JPanel gridPanel = new JPanel(new GridLayout(1, 1));
gridPanel.add(new JButton("hello"));
getContentPane().add(gridPanel);
}
public static void main(String[] args)
{
TestFrame frame = new TestFrame();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
}
}
Try the above program. The button will cover whole area when you maximize the frame.
If you show code of your panel it will be easier to see why it does not expand.
*** frame ***
public class MainScreen extends JFrame
{
private Container c;
public MainScreen() {
c = getContentPane();
MainScrn_FullPanel m = new MainScrn_FullPanel();
c.add(m);
}
public static void main (String args[]) {
MainScreen main_scr = new MainScreen ();
main_scr.show();
main_scr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
main_scr.setExtendedState(main_scr.getExtendedState()|JFrame.MAXIMIZED_BOTH);
main_scr.setSize(260,700);
main_scr.setLocation(350,40);
main_scr.setVisible(true);
}
}
*** MainScrn_FullPanel.java ***
public class MainScrn_FullPanel extends JPanel {
private JLabel TopPic, lbl_displayName;
private JPanel TreeArea, TreeArea2, TopLayer;
public MainScrn_FullPanel() {
MainScrn_HeaderPanel headerPanel = new MainScrn_HeaderPanel();
MainScrn_ContactListPanel contactPanel = new MainScrn_ContactListPanel();
TreeArea = new JPanel(new BorderLayout());
TreeArea2 = new JPanel(new BorderLayout());
TreeArea2.add(lbl_displayName, BorderLayout.NORTH);
TreeArea2.add(contactPanel, BorderLayout.SOUTH);
TreeArea.add(TopLayer,BorderLayout.NORTH);
TreeArea.add(headerPanel,BorderLayout.CENTER);
TreeArea.add(TreeArea2,BorderLayout.SOUTH);
add(TreeArea);
}
}
it's kind of simplified of the actual program.
anyone who is able to help me with this problem?
URGENT !!!!
zHuZhu
anyone who is able to help me with this problem?
URGENT !!!!
zHuZhu
If it's that urgent then I suggest you hire somebody to do your programming. That way you'll have control of their time. If you want us to help you, you'll have to wait until we're ready. It's your choice. So don't tell us it's urgent because that's just annoying and we don't care.
Besides, you have already been told to use a suitable layout manager. You could google for "layout manager tutorial" for more help with that.
Or if you want to get the attention of people who are more competent in Swing, you could in future consider posting Swing questions in the Swing forum.
Compare the code posted in reply 5 with your code posted in reply 6.
Which code is easier to read and understand?
Instead of posting "URGENT" all the time, why don't you figure out how to use the forum properly.
If you can't take the time to learn how to use the forum "code formatting tags", I'm not going to take the time to read your unformatted code.