<bdo id='qLGVG'></bdo><ul id='qLGVG'></ul>
    <tfoot id='qLGVG'></tfoot>

    1. <small id='qLGVG'></small><noframes id='qLGVG'>

      <i id='qLGVG'><tr id='qLGVG'><dt id='qLGVG'><q id='qLGVG'><span id='qLGVG'><b id='qLGVG'><form id='qLGVG'><ins id='qLGVG'></ins><ul id='qLGVG'></ul><sub id='qLGVG'></sub></form><legend id='qLGVG'></legend><bdo id='qLGVG'><pre id='qLGVG'><center id='qLGVG'></center></pre></bdo></b><th id='qLGVG'></th></span></q></dt></tr></i><div id='qLGVG'><tfoot id='qLGVG'></tfoot><dl id='qLGVG'><fieldset id='qLGVG'></fieldset></dl></div>
      <legend id='qLGVG'><style id='qLGVG'><dir id='qLGVG'><q id='qLGVG'></q></dir></style></legend>

        有什么办法可以旋转这个 90 度吗?

        Is there any way I can rotate this 90 degrees?(有什么办法可以旋转这个 90 度吗?)
      1. <i id='rrTqY'><tr id='rrTqY'><dt id='rrTqY'><q id='rrTqY'><span id='rrTqY'><b id='rrTqY'><form id='rrTqY'><ins id='rrTqY'></ins><ul id='rrTqY'></ul><sub id='rrTqY'></sub></form><legend id='rrTqY'></legend><bdo id='rrTqY'><pre id='rrTqY'><center id='rrTqY'></center></pre></bdo></b><th id='rrTqY'></th></span></q></dt></tr></i><div id='rrTqY'><tfoot id='rrTqY'></tfoot><dl id='rrTqY'><fieldset id='rrTqY'></fieldset></dl></div>

        <small id='rrTqY'></small><noframes id='rrTqY'>

      2. <tfoot id='rrTqY'></tfoot>

          • <bdo id='rrTqY'></bdo><ul id='rrTqY'></ul>

                  <legend id='rrTqY'><style id='rrTqY'><dir id='rrTqY'><q id='rrTqY'></q></dir></style></legend>
                    <tbody id='rrTqY'></tbody>
                • 本文介绍了有什么办法可以旋转这个 90 度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是我当前的代码:

                  包日历;导入 java.awt.event.ActionEvent;导入 java.awt.event.ActionListener;导入 java.text.SimpleDateFormat;导入 java.util.Date;导入 javax.swing.JFrame;导入 javax.swing.JLabel;导入 javax.swing.JPanel;导入 javax.swing.Timer;公共类时钟扩展 JLabel {私有字符串模式;私人定时器定时器;公共时钟(字符串模式){this.pattern = 模式;创建定时器();计时器.start();}公共时钟(){模式=hh:mm:ss a";创建定时器();计时器.start();}私人无效createTimer(){计时器 = 新计时器(0,新 ActionListener(){@覆盖公共无效actionPerformed(ActionEvent arg0){setText(new SimpleDateFormat(pattern).format(new Date()));}});}公共静态无效主要(字符串[]参数){JFrame 框架 = 新的 JFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);JPanel contentPane = new JPanel();frame.setContentPane(contentPane);时钟 digitalClock = new Clock();contentPane.add(digitalClock);frame.setVisible(true);}}

                  我终其一生都无法弄清楚如何旋转它.我查看了其他几个论坛,但没有其他人与此问题有关.

                  据我所知,没有办法旋转 JPanel 或 JFrame,所以我不走运吗?

                  这就是现在的样子:

                  ,我建议,如果你有兴趣,你可以拿一份副本并将其存放在安全的地方.

                  This is my current code:

                  package Calendar;
                  
                  import java.awt.event.ActionEvent;
                  import java.awt.event.ActionListener;
                  import java.text.SimpleDateFormat;
                  import java.util.Date;
                  import javax.swing.JFrame;
                  import javax.swing.JLabel;
                  import javax.swing.JPanel;
                  import javax.swing.Timer;
                  
                  public class Clock extends JLabel {
                      private String pattern;
                      private Timer timer;
                  
                  public Clock(String pattern){
                      this.pattern = pattern;
                      createTimer();
                      timer.start();
                  }
                  
                  public Clock(){
                      pattern = "hh:mm:ss a";
                      createTimer();
                      timer.start();
                  }
                  
                  private void createTimer(){
                      timer = new Timer(0, new ActionListener() {
                          @Override
                          public void actionPerformed(ActionEvent arg0) {
                              setText(new SimpleDateFormat(pattern).format(new Date()));
                          }
                      });
                  }
                  
                  public static void main(String[] args){
                      JFrame frame = new JFrame();
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      JPanel contentPane = new JPanel();
                      frame.setContentPane(contentPane);
                      Clock digitalClock = new Clock();
                      contentPane.add(digitalClock);
                      frame.setVisible(true);
                  }
                  }
                  

                  and I cannot for the life of me figure out how to get this rotated. I looked on several other forums but there was no body else with this issue.

                  As far as I can tell there is no way to rotate either a JPanel or JFrame so am I out of luck?

                  This is what it looks like right now:

                  Digital Clock

                  And I would like to get it so the text is rotated 90 degrees. basically vertical.

                  EDIT: SOLUTION:

                      package Calendar;
                  
                  import java.awt.event.ActionEvent;
                  import java.awt.event.ActionListener;
                  import java.text.SimpleDateFormat;
                  import java.util.Date;
                  import javax.swing.JLabel;
                  import javax.swing.Timer;
                  import java.awt.*;
                  import java.awt.geom.*;
                  
                  public class Clock extends JLabel {
                  
                      private String pattern;
                      private Timer timer;
                  
                      public Clock ()
                      {
                          super();
                          pattern = "hh:mm:ss a";
                          createTimer();
                          timer.start();
                      }
                  
                      public Clock(String pattern)
                      {
                          super (pattern);
                          this.pattern = pattern;
                          createTimer();
                          timer.start();
                      }
                  
                      private void createTimer(){
                          timer = new Timer(0, new ActionListener() {
                              @Override
                              public void actionPerformed(ActionEvent arg0) {
                                  setText(new SimpleDateFormat(pattern).format(new Date()));
                              }
                          });
                      }
                  
                      public void paint (Graphics g)
                      {
                          if (g instanceof Graphics2D) {
                              Graphics2D g2 = (Graphics2D) g;
                              AffineTransform flipTrans = new AffineTransform();
                              double widthD = (double) getWidth();
                              flipTrans.setToRotation(-Math.PI / 2.0, getWidth() / 2.0, getHeight() / 2.0);
                              g2.setTransform(flipTrans);
                              super.paint(g);
                          } else {
                              super.paint(g);
                          }
                      }
                  }
                  

                  解决方案

                  This is based on this example and makes use of JXLayer to physically rotate the label component the way you want it.

                  It also saves you from having to do any custom painting of your own.

                  I've used a similar technique to rotate JTabbedPane tabs so they run vertically down the side of the JTabbedPane

                  import java.awt.BorderLayout;
                  import java.awt.EventQueue;
                  import java.awt.event.ActionEvent;
                  import java.awt.event.ActionListener;
                  import java.text.SimpleDateFormat;
                  import java.util.Date;
                  import javax.swing.JComponent;
                  import javax.swing.JFrame;
                  import javax.swing.JLabel;
                  import javax.swing.JPanel;
                  import javax.swing.JSlider;
                  import javax.swing.Timer;
                  import javax.swing.UIManager;
                  import javax.swing.UnsupportedLookAndFeelException;
                  import javax.swing.event.ChangeEvent;
                  import javax.swing.event.ChangeListener;
                  import org.jdesktop.jxlayer.JXLayer;
                  import org.pbjar.jxlayer.demo.TransformUtils;
                  import org.pbjar.jxlayer.plaf.ext.transform.DefaultTransformModel;
                  
                  public class RotateClock {
                  
                      public static void main(String[] args) {
                          new RotateClock();
                      }
                  
                      public RotateClock() {
                          EventQueue.invokeLater(new Runnable() {
                              @Override
                              public void run() {
                                  try {
                                      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                                  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                                  }
                  
                                  JFrame frame = new JFrame();
                                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                  frame.setLayout(new BorderLayout());
                                  frame.add(new ExamplePane());
                                  frame.pack();
                                  frame.setLocationRelativeTo(null);
                                  frame.setVisible(true);
                              }
                          });
                      }
                  
                      public class ExamplePane extends JPanel {
                  
                          private JSlider slider;
                          private Clock clock;
                          private DefaultTransformModel transformModel;
                  
                          public ExamplePane() {
                  
                              setLayout(new BorderLayout());
                  
                              slider = new JSlider(0, 360);
                              slider.setValue(0);
                              slider.setSnapToTicks(true);
                              slider.setPaintTicks(true);
                              slider.setMajorTickSpacing(10);
                              slider.addChangeListener(new ChangeListener() {
                                  @Override
                                  public void stateChanged(ChangeEvent e) {
                  
                                      transformModel.setRotation(Math.toRadians(slider.getValue()));
                  
                                  }
                              });
                  
                              clock = new Clock();
                  
                              transformModel = new DefaultTransformModel();
                              transformModel.setRotation(Math.toRadians(0));
                              transformModel.setScaleToPreferredSize(true);
                              JXLayer<JComponent> rotatePane = TransformUtils.createTransformJXLayer(clock, transformModel);
                  
                              add(slider, BorderLayout.NORTH);
                              add(rotatePane);
                  
                          }
                      }
                  
                      public class Clock extends JLabel {
                  
                          private String pattern;
                          private Timer timer;
                  
                          public Clock(String pattern) {
                              this.pattern = pattern;
                              setText(new SimpleDateFormat(pattern).format(new Date()));
                              createTimer();
                              timer.start();
                          }
                  
                          public Clock() {
                              this("hh:mm:ss a");
                          }
                  
                          private void createTimer() {
                              timer = new Timer(0, new ActionListener() {
                                  @Override
                                  public void actionPerformed(ActionEvent arg0) {
                                      setText(new SimpleDateFormat(pattern).format(new Date()));
                                  }
                              });
                              timer.setInitialDelay(0);
                          }
                      }
                  
                  }
                  

                  This deals with, amongst other things, oddities with mouse events and the preferred size of the component.

                  Unfortunately, the code required to perform the transformation (Piet's examples) is no longer available on the net

                  I've put all the source code of JXLayer (version 3) and Piet's examples into a single zip and I would suggest, if you are interested, you grab a copy and store it some where safe.

                  这篇关于有什么办法可以旋转这个 90 度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                    • <bdo id='ucHP7'></bdo><ul id='ucHP7'></ul>

                          <tbody id='ucHP7'></tbody>

                      • <legend id='ucHP7'><style id='ucHP7'><dir id='ucHP7'><q id='ucHP7'></q></dir></style></legend>

                        • <i id='ucHP7'><tr id='ucHP7'><dt id='ucHP7'><q id='ucHP7'><span id='ucHP7'><b id='ucHP7'><form id='ucHP7'><ins id='ucHP7'></ins><ul id='ucHP7'></ul><sub id='ucHP7'></sub></form><legend id='ucHP7'></legend><bdo id='ucHP7'><pre id='ucHP7'><center id='ucHP7'></center></pre></bdo></b><th id='ucHP7'></th></span></q></dt></tr></i><div id='ucHP7'><tfoot id='ucHP7'></tfoot><dl id='ucHP7'><fieldset id='ucHP7'></fieldset></dl></div>
                          1. <small id='ucHP7'></small><noframes id='ucHP7'>

                            <tfoot id='ucHP7'></tfoot>