Swing控件可以实现水平翻转,有看到过阿拉伯国家软件的就知道他们的写作习惯是从右到左的形式,SUN公司为了方便不同客户为Swing控件提供两个实现翻转效果的方法applyComponentOrientation(ComponentOrientationorientation)
创新互联建站是一家专注于网站设计、做网站与策划设计,乐陵网站建设哪家好?创新互联建站做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:乐陵等地区。乐陵做网站价格咨询:028-86922220
设置此组件及其包含的所有组件的ComponentOrientation属性。setComponentOrientation(ComponentOrientationo)
设置语言敏感的方向,用于排序此组件内的元素或文本。
下面的代码建议在JDK1.6上面运行,Swing控件布局采用1.6的类
- importjava.awt.ComponentOrientation;
- importjava.awt.event.ActionEvent;
- importjava.awt.event.ActionListener;
- publicclassNewJFrameextendsjavax.swing.JFrame{
- publicNewJFrame(){
- initComponents();
- jButton1.setActionCommand("jbutton1");
- jButton1.addActionListener(newJButton_ActionListener(this));
- jButton2.setActionCommand("jbutton2");
- jButton2.addActionListener(newJButton_ActionListener(this));
- }
- //<editor-folddefaultstateeditor-folddefaultstate="collapsed"
desc="GeneratedCode">- privatevoidinitComponents(){
- jComboBox1=newjavax.swing.JComboBox();
- jButton1=newjavax.swing.JButton();
- jButton2=newjavax.swing.JButton();
- jCheckBox1=newjavax.swing.JCheckBox();
- jRadioButton1=newjavax.swing.JRadioButton();
- jScrollPane1=newjavax.swing.JScrollPane();
- jTree1=newjavax.swing.JTree();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jComboBox1.setModel(newjavax.swing.DefaultComboBoxModel(newString[]
{"Item1","Item2","Item3","Item4"}));- jButton1.setText("jButton1");
- jButton2.setText("jButton2");
- jCheckBox1.setText("jCheckBox1");
- jRadioButton1.setText("jRadioButton1");
- jScrollPane1.setViewportView(jTree1);
- javax.swing.GroupLayoutlayout=newjavax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,layout.createSequentialGroup()
- .addGap(22,22,22)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jRadioButton1,javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,174,Short.MAX_VALUE)- .addComponent(jCheckBox1,javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,174,Short.MAX_VALUE)- .addComponent(jComboBox1,javax.swing.GroupLayout.Alignment.LEADING,
0,174,Short.MAX_VALUE))- .addGap(29,29,29)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.
Alignment.LEADING,false)- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1,javax.swing.GroupLayout.PREFERRED_SIZE,109,
javax.swing.GroupLayout.PREFERRED_SIZE)- .addGap(26,26,26)
- .addComponent(jButton2,javax.swing.GroupLayout.PREFERRED_SIZE,106,
javax.swing.GroupLayout.PREFERRED_SIZE))- .addComponent(jScrollPane1))
- .addGap(234,234,234))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.
Alignment.TRAILING,false)- .addComponent(jButton2,javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.
DEFAULT_SIZE,Short.MAX_VALUE)- .addComponent(jButton1,javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.
DEFAULT_SIZE,Short.MAX_VALUE)- .addComponent(jComboBox1,javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,37,Short.MAX_VALUE))- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jCheckBox1,javax.swing.GroupLayout.PREFERRED_SIZE,34,
javax.swing.GroupLayout.PREFERRED_SIZE)- .addGap(18,18,18)
- .addComponent(jRadioButton1,javax.swing.GroupLayout.PREFERRED_SIZE,35,
javax.swing.GroupLayout.PREFERRED_SIZE))- .addComponent(jScrollPane1,javax.swing.GroupLayout.PREFERRED_SIZE,250,
javax.swing.GroupLayout.PREFERRED_SIZE))- .addContainerGap(86,Short.MAX_VALUE))
- );
- pack();
- }//
- publicstaticvoidmain(Stringargs[]){
- finalNewJFramenewJFrame=newNewJFrame();
- java.awt.EventQueue.invokeLater(newRunnable(){
- publicvoidrun(){
- newJFrame.setVisible(true);
- }
- });
- }
- publicvoidjButton1_ActionListener()
- {
- this.getContentPane().applyComponentOrientation
(ComponentOrientation.LEFT_TO_RIGHT);- this.getRootPane().updateUI();
- }
- publicvoidjButton2_ActionListener()
- {
- this.getContentPane().applyComponentOrientation
(ComponentOrientation.RIGHT_TO_LEFT);- this.getRootPane().updateUI();
- }
- //Variablesdeclaration-donotmodify
- privatejavax.swing.JButtonjButton1;
- privatejavax.swing.JButtonjButton2;
- privatejavax.swing.JCheckBoxjCheckBox1;
- privatejavax.swing.JComboBoxjComboBox1;
- privatejavax.swing.JRadioButtonjRadioButton1;
- privatejavax.swing.JScrollPanejScrollPane1;
- privatejavax.swing.JTreejTree1;
- //Endofvariablesdeclaration
- }
- classJButton_ActionListenerimplementsActionListener
- {
- privateNewJFramenewJFrame;
- publicJButton_ActionListener(NewJFramenewJFrame)
- {
- this.newJFrame=newJFrame;
- }
- publicvoidactionPerformed(ActionEvente){
- if("jbutton1".equals(e.getActionCommand()))
- {
- this.newJFrame.jButton1_ActionListener();
- }elseif("jbutton2".equals(e.getActionCommand()))
- {
- this.newJFrame.jButton2_ActionListener();
- }
- }
- }
【编辑推荐】
分享标题:Swing控件可以实现水平翻转
文章地址:http://www.shufengxianlan.com/qtweb/news40/209440.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联