How to align two JButtons to be right aligned?

So currently my program shows only one of the buttons in the bottom right hand of the GUI. But I want to show both buttons in the bottom right hand corner. Any ideas how to set both buttons to the right corner? Here is my code so far:

import javax.swing.*;

import java.awt.*;

public class Other extends JFrame{
        private static final long serialVersionUID = 1L;
        public Other() {
            super("Buttons");
            final Container mainPanel = getContentPane();
            mainPanel.setLayout(new BorderLayout());
            JPanel buttonPanel = new JPanel();
            buttonPanel.setLayout(new BorderLayout());
            JPanel inputPanel = new JPanel();
            inputPanel.add(new JLabel("RANDOM TEXT HERE"));
            inputPanel.add(new JLabel("RANDOM TEXT HERE"));
            inputPanel.add(new JLabel("RANDOM TEXT HERE"));
            JButton s = new JButton("first");
            JButton l = new JButton("second");
            buttonPanel.add(s,BorderLayout.LINE_END);
            buttonPanel.add(l,BorderLayout.LINE_END); //<-- not working
            mainPanel.add(inputPanel,BorderLayout.PAGE_START);
            mainPanel.add(buttonPanel,BorderLayout.PAGE_END);
            pack();
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLocationRelativeTo(null);
            setVisible(true);
        }
   public static void main(String[] args){
       Other o = new Other();
   }
}

Answers


buttonPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));

While the BorderLayout will only accept one component per layout area, FlowLayout will display as many as are added (within viewable bounds).


Need Your Help

how to spoof hostname in syslog messages?

logging ubuntu rsyslog

I am logging messages like this in perl -

Apache Wicket replace fragements of the RIA application (web-site :)) without page refresh

jquery wicket ria

we are currently in the process of analyzing different JS and web-frameworks.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.