我想知道如何在此JLabel的右下角添加JFrame?我对编码还相当陌生,因此我将以此作为学习经验。:)

public class MainQuestions  {

    public static void main (String args[]){
        JFrame frame=new JFrame();
        Object ARRAY[]={"French","English","Portugese","Spanish"};
        String answer=(String)JOptionPane.showInputDialog(frame, "What language  predominately spoken in Latin American countries?","World Geography Review", JOptionPane.PLAIN_MESSAGE, null, ARRAY, null);

        if(answer == null) {
            //System.exit(0);
        } else if(answer.equals("Spanish")) {
            JOptionPane.showMessageDialog(null, "Correct!", "World Geography Review", JOptionPane.PLAIN_MESSAGE,null);
            //System.exit(0);
        } else {
            JOptionPane.showMessageDialog(null, "Sorry, wrong answer.", "World Geography Review", JOptionPane.PLAIN_MESSAGE,null);
            //System.exit(0);
        }
    }
}

最佳答案

我使用BorderLayout为您创建了一个示例

public class Test {


    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

    private static void createAndShowGUI() {
        JFrame f = new JFrame("Test label");
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JLabel label = new JLabel("Test");
        //this set component orientation to the right!
        label.setHorizontalAlignment(JLabel.TRAILING);
        f.add(label,BorderLayout.SOUTH);
        f.setLocationByPlatform(true);
        f.pack();
        f.setVisible(true);
    }
}


输出:



有关挥杆的更多信息,请开始阅读此tutorials

关于java - 如何在此添加JLabel?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22429390/

10-09 02:38