'How to show the Button in the bottom of the JScrollPane Inside a JFrame

I am working on an application in which I am trying to show a banner in a JFrame. Inside the JFrame, I using a JScrollbar which is using JEditorPane to display content of a HTML page.

    public static JFrame ShowBanner() throws IOException {
        int width = 0;
        int height = 0;
        String urlText = null;
        String ScrnResol = getScreenResolution();
        String[] ScreenResolution = ScrnResol.split(",");
        try {
            width = Integer.parseInt(ScreenResolution[0]);
            height = Integer.parseInt(ScreenResolution[1]);
        } catch (NumberFormatException nfe) {
            logger.error("NumberFormatException: " + nfe.getMessage());
        }
        //Creating Frame
        frmOpt = new JFrame("Banner");
        frmOpt.setExtendedState(JFrame.MAXIMIZED_BOTH);
        frmOpt.setPreferredSize(new Dimension(width, height));
        frmOpt.setUndecorated(true);
        frmOpt.setBackground(new Color(1.0f, 1.0f, 1.0f, 0.1f));
        frmOpt.setVisible(true);
        frmOpt.setAlwaysOnTop(true);
        frmOpt.setLocationRelativeTo(null);
        //bringToForeground(getHWND(frmOpt));
        JPanel panel = new JPanel();
        LayoutManager layout = new FlowLayout();
        panel.setLayout(layout);
        JEditorPane jEditorPane = new JEditorPane();
        jEditorPane.setEditable(false);
        try {
            
            String urlText=IOUtils.toString(BringUpFrame.class.getClassLoader().getResourceAsStream("banner.htm"));
            jEditorPane.setContentType("text/html");
            jEditorPane.setText(urlText);
        } catch (Exception e) {
            logger.error("Exception while executing showBanner: {}", e);
            jEditorPane.setContentType("text/html");
            jEditorPane.setText("<html>Page not found.</html>");
        }
        JScrollPane jScrollPane = new JScrollPane(jEditorPane);
        scrollPane.setColumnHeaderView(createButton());
        jScrollPane.setPreferredSize(new Dimension(width, height));
        panel.add(jScrollPane);
        frmOpt.add(panel);
        frmOpt.pack();
        frmOpt.setVisible(true);
        return frmOpt;

   }

   private static JPanel createButton() {
        JPanel panel = new JPanel();
        panel.setBackground(new Color(1.0f, 1.0f, 1.0f, 0.1f));
        JButton button = new JButton("Close");
        panel.add(button);
        return panel;
    }

Currently the view is looking like this:

enter image description here

As of Now button is displayed on the Top. What I want to do is to put the button in the bottom of the screen. I have tried some layout (BoxLayout and BorderLayout) but view was as per the expection. I can understand that it will be a small change but I am not having much exp in Swing Programming.

Can someone please suggest how can I achieve that.

Edit:

Tried suggested changes:

JScrollPane jScrollPane = new JScrollPane(jEditorPane);
panel.add(jScrollPane);
frmOpt.add(panel,BorderLayout.CENTER);
frmOpt.add(createButton(),BorderLayout.PAGE_END);

but it's not coming as expected. Button and html page in JscrollPane are displaying completely separated and Page is also not coming over complete screen. enter image description here

Thanks,



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source