开发者

Reloading component Frame

I'm Wo开发者_JAVA百科rking on time schedule booking application , when I run the project it shows component(total frame) , however i want that when the button is pressed to reload ,component should be spitted.(two frames with one below other by spilt) ???


Based on your description I think you need to either add splitpane in frame on click of a button or you already have a splitpane in frame and want to add panel in it on click of button.

For first option you can do something like this:

    final JFrame frame = new JFrame("Split test");
    frame.setSize(400, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JPanel jPanel2 = new JPanel();
    JLabel jLabel = new JLabel("I am added by click on button");
    jPanel2.add(jLabel);

    final JPanel jPanel = new JPanel();
    JButton button = new JButton("Click me to add pane in split");
    jPanel.add(button);

    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
            pane.add(jPanel);
            pane.add(jPanel2);
            pane.setDividerLocation(frame.getHeight()/2); // set Divider location.
            frame.remove(jPanel);
            frame.add(pane);
            frame.validate();
        }
    });

    frame.add(jPanel);
    frame.setVisible(true);

If you are stuck in later one then try this:

    final JFrame frame = new JFrame("Split test");
    frame.setSize(400, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    frame.add(pane);

    pane.setEnabled(false); // stop user from clicking on divider of split pane.

    final JPanel jPanel2 = new JPanel();
    JLabel jLabel = new JLabel("I am added by click on button");
    jPanel2.add(jLabel);

    final JPanel jPanel = new JPanel();
    JButton button = new JButton("Click me to add pane in split");
    jPanel.add(button);
    pane.add(jPanel);

    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            pane.add(jPanel2);
            pane.setDividerLocation(frame.getHeight()/2); // set Divider location.
            pane.setEnabled(true); // let user change divider location.
        }
    });

    frame.setVisible(true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜