我想知道如何在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);
}
}
}
答案 0 :(得分:2)
我使用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
的详细信息答案 1 :(得分:0)
这样的事情应该有效。问我你是否有问题:)
setLayout(new BorderLayout());
JPanel labelPanel = new JPanel();
labelPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
JLabel bottomRtLabel = new JLabel("BOTTOM RIGHT LABEL");
labelPanel.add(bottomRtLabel);
frame.add(labelPanel,BorderLayout.SOUTH);
答案 2 :(得分:0)
这里有一些非常小的例子可以帮助你理解这个:
public class Example extends JFrame {
public Example() {
setLayout(new BorderLayout());
add(new JButton("Button"), BorderLayout.PAGE_START);
add(new JLabel("Label"), BorderLayout.PAGE_END);
setSize(800, 600);
setVisible(true);
}
public static void main(String[] args) {
new Example();
}
}