public class test { public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() { @Override
public void run() {
try {
UIManager.setLookAndFeel(new org.jvnet.substance.skin.SubstanceBusinessLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
test.name in=new test().new name();
in.init(); }
});
} public class name{ public void init() {
JTextField textField1_1=new JTextField("是不是居中");
textField1_1.setSize(150, 30);
textField1_1.setLocation(20, 20);
textField1_1.setHorizontalAlignment(JTextField.CENTER);
JTextField textField1_2=new JTextField("是不是居中2");
textField1_2.setSize(150, 30);
textField1_2.setLocation(70, 70);
textField1_2.setHorizontalAlignment(JTextField.RIGHT);
JButton alter = new JButton("信息修改");
alter.setSize(80, 30);
alter.setLocation(100, 120);
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame jframe=new JFrame("UIDEMO");
jframe.setLocationRelativeTo(null);
jframe.setLayout(null);
jframe.setSize(400, 200);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setVisible(true);
jframe.add(textField1_1);
jframe.add(textField1_2);
jframe.add(alter);
}
}
}
上面代码是这种效果:注释掉使用substance的语句后]public class test { public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() { @Override
public void run() {
// try {
// UIManager.setLookAndFeel(new org.jvnet.substance.skin.SubstanceBusinessLookAndFeel());
// } catch (UnsupportedLookAndFeelException e) {
// // TODO 自动生成的 catch 块
// e.printStackTrace();
// }
test.name in=new test().new name();
in.init(); }
});
} public class name{ public void init() {
JTextField textField1_1=new JTextField("是不是居中");
textField1_1.setSize(150, 30);
textField1_1.setLocation(20, 20);
textField1_1.setHorizontalAlignment(JTextField.CENTER);
JTextField textField1_2=new JTextField("是不是居中2");
textField1_2.setSize(150, 30);
textField1_2.setLocation(70, 70);
textField1_2.setHorizontalAlignment(JTextField.RIGHT);
JButton alter = new JButton("信息修改");
alter.setSize(80, 30);
alter.setLocation(100, 120);
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame jframe=new JFrame("UIDEMO");
jframe.setLocationRelativeTo(null);
jframe.setLayout(null);
jframe.setSize(400, 200);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setVisible(true);
jframe.add(textField1_1);
jframe.add(textField1_2);
jframe.add(alter);
}
}是这种效果:为什么使用substance.jar后JTextField中文字不能居中或者右对齐
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货