我有(2)JTextAreas(输入文本&输出文本)
(2)JComboBoxes(自动检测& TranslateTo)
请看照片连接到看看目标是什么。
我想用某个布局管理器来获得这个布局我已经试过了FlowLayout,SpringLayout并且没有用这些获得理想的结果。这里是我的代码
public class translate extends JFrame implements ActionListener{
/*
Our Langauges of choice we can add more if desired in the future
*/
String[] nativeString = { "Auto-Detect"};
String[] translateString = { "Español", "中文", "Francais", "Italiano", "Deutsche" , "English" };
JComboBox nativeLanguage;
JComboBox translateTo;
JButton execute;
final JPanel topRight;
final JPanel topLeft;
final JPanel bottomLeft;
JPanel bottomRight;
JLabel tR;
JLabel tL;
JLabel bR;
JLabel bL;
JRadioButton local;
JRadioButton mainArea;
JTextArea input;
JTextArea output;
public translate() throws Exception{
super("Translation Service");
JOptionPane.showMessageDialog(null, "Translation Services Require A NetWork Function To Make Calls");
Translate.setClientId("xxxxxxxxx");
Translate.setClientSecret("Xxxxxxxxxxxx);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(700,400);
setLocationRelativeTo(null);
setResizable(true);
setLookAndFeel();
SpringLayout spring = new SpringLayout();
setLayout(spring);
input= new JTextArea();
JScrollPane inScroll = new JScrollPane();
input.add(inScroll);
input.setEditable(true);
input.setLineWrap(true);
execute = new JButton("Translate");
execute.addActionListener(this);
output = new JTextArea();
JScrollPane outScroll = new JScrollPane();
output.add(outScroll);
output.setEditable(true);
output.setLineWrap(true);
output.setVisible(true);
/*
Our JComboBoxes for user to selct langauge they want to choose
*/
nativeLanguage = new JComboBox(nativeString);
translateTo = new JComboBox(translateString);
nativeLanguage.addActionListener(this);
translateTo.addActionListener(this);
// JLabels
tR = new JLabel("Auto-Detect");
tL = new JLabel ("Target Langauge");
// FlowLayout fl = new FlowLayout();
SpringLayout sp = new SpringLayout();
setLayout(sp);
// setLayout(fl);
//1
topRight = new JPanel();
// topRight.setLayout(new BoxLayout(topRight, BoxLayout.PAGE_AXIS));
topRight.add(nativeLanguage);
topRight.add(tR);
//2
topLeft = new JPanel();
// topLeft.setLayout(new BoxLayout(topLeft, BoxLayout.PAGE_AXIS));
topLeft.add(translateTo);
topLeft.add(tL);
//3
bottomRight = new JPanel();
// bottomRight.setLayout(new BoxLayout(bottomRight, BoxLayout.PAGE_AXIS));
bottomRight.add(input);
//4
bottomLeft = new JPanel();
// bottomLeft.setLayout(new BoxLayout(bottomLeft, BoxLayout.LINE_AXIS));
bottomLeft.add(output);
add(topRight, SpringLayout.NORTH);
add(topLeft, SpringLayout.NORTH);
add(bottomRight, SpringLayout.SOUTH);
add(bottomLeft, SpringLayout.SOUTH);
setVisible(true);
}
使用尽可能多的,因为你需要达到你所需要的结果,布局一般不是单一的水平,但我们构成了n深度的容器,每个集中在一个给定区域的个人需求,并建立起来,产生你想要的所有效果 – MadProgrammer
感谢MadProgrammer,是的,我相信我已经包括这是最好的布局(网格布局)已经插入不同的布局,这似乎更容易在这种情况下工作和定制;试图调整一切在这一刻或至少我的jtextareas,因为看起来更像是textfields – TravJav92
对于我的钱,我会使用复合'GridBagLayout's,但这就是我 – MadProgrammer