Przeglądaj źródła

页面布局随全屏而适应

17491 4 dni temu
rodzic
commit
39c4800d08
2 zmienionych plików z 35 dodań i 13 usunięć
  1. 2 4
      src/com/mes/ui/LoginFarme.java
  2. 33 9
      src/com/mes/ui/MesClient.java

+ 2 - 4
src/com/mes/ui/LoginFarme.java

@@ -190,15 +190,13 @@ public class LoginFarme extends JFrame {
                     if(MesClient.jfxPanel == null){
                         String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/work?oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn;
                         MesClient.jfxPanel = new MesWebView(url);
-                        MesClient.jfxPanel.setSize(990, 550);
-                        MesClient.indexPanelB.add(MesClient.jfxPanel);
+                        MesClient.indexPanelB.add(MesClient.jfxPanel, BorderLayout.CENTER);
                     }
 
                     if(MesClient.jfxPanel2 == null){
                         String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProcessCheckRecord/ulist?ucode="+user_id+"&oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn;
                         MesClient.jfxPanel2 = new MesWebView(url);
-                        MesClient.jfxPanel2.setSize(990, 550);
-                        MesClient.indexPanelC.add(MesClient.jfxPanel2);
+                        MesClient.indexPanelC.add(MesClient.jfxPanel2, BorderLayout.CENTER);
                     }
 
                     MesClient.initWarehouseData();

+ 33 - 9
src/com/mes/ui/MesClient.java

@@ -35,6 +35,34 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
 public class MesClient extends JFrame {
+
+    /** Keeps the fixed-size operator controls centered when the workstation uses a large display. */
+    private static class CenteredPanel extends JPanel {
+        private final int contentWidth;
+        private final int contentHeight;
+
+        CenteredPanel(int contentWidth, int contentHeight) {
+            this.contentWidth = contentWidth;
+            this.contentHeight = contentHeight;
+            setLayout(null);
+            setPreferredSize(new Dimension(contentWidth, contentHeight));
+        }
+
+        @Override
+        public void doLayout() {
+            int x = Math.max(0, (getWidth() - contentWidth) / 2);
+            int y = Math.max(0, (getHeight() - contentHeight) / 2);
+            for (Component child : getComponents()) {
+                JComponent component = (JComponent) child;
+                Rectangle bounds = (Rectangle) component.getClientProperty("designBounds");
+                if (bounds == null) {
+                    bounds = child.getBounds();
+                    component.putClientProperty("designBounds", new Rectangle(bounds));
+                }
+                child.setLocation(bounds.x + x, bounds.y + y);
+            }
+        }
+    }
     public static final Logger log = LoggerFactory.getLogger(MesClient.class);
 
     public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
@@ -386,10 +414,6 @@ public class MesClient extends JFrame {
         setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         // Maximize within the desktop work area so the system taskbar remains visible.
-        setMaximizedBounds(GraphicsEnvironment.getLocalGraphicsEnvironment()
-                .getMaximumWindowBounds());
-        setExtendedState(JFrame.MAXIMIZED_BOTH);
-        validate();
 
         JMenuBar menuBar = new JMenuBar();
         menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
@@ -533,7 +557,7 @@ public class MesClient extends JFrame {
         contentPane.add(tabbedPane);
 
         //首页
-        JPanel indexPanelA = new JPanel();
+        JPanel indexPanelA = new CenteredPanel(972, 450);
         indexScrollPaneA = new JScrollPane(indexPanelA);
         indexPanelA.setLayout(null);
 
@@ -642,22 +666,22 @@ public class MesClient extends JFrame {
 
 //		searchScrollPane = new JScrollPane((Component) null);
 
-        indexPanelC = new JPanel();
+        indexPanelC = new JPanel(new BorderLayout());
         searchScrollPaneDj = new JScrollPane(indexPanelC);
-        indexPanelC.setLayout(null);
 
         tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
 
 
-        indexPanelB = new JPanel();
+        indexPanelB = new JPanel(new BorderLayout());
         searchScrollPane = new JScrollPane(indexPanelB);
-        indexPanelB.setLayout(null);
 
 		tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
 
         // 确保窗口布局正确
         pack();
         setSize(1024, 768);
+        setMaximizedBounds(GraphicsEnvironment.getLocalGraphicsEnvironment()
+                .getMaximumWindowBounds());
         validate();
         repaint();