|
/**工具栏JToolBar采用从左开始的FlowLayout布局*/ JToolBar toolBar = new JToolBar(); toolBar.setBorderPainted(false); //不画边界 toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
/**窗体采用动态的BorderLayout布局,通过获取工具栏或状态栏的复选标记进行界面的动态调整*/ JSplitPane splitPane = new JSplitPane(); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); //设置统计窗口分隔条的方向 splitPane.setDividerLocation(300); //设置分隔条的位置 splitPane.setOneTouchExpandable(true); JCheckBoxMenuItem toolBarItem = new JCheckBoxMenuItem("工具栏(T)", true); JLabel statusLabel = new JLabel("当前统计目标:"); JCheckBoxMenuItem statusBarItem = new JCheckBoxMenuItem("状态栏(S)", true);
/**设置系统窗体布局并动态设置工具栏和状态栏*/ private void setLayout() { if (toolBarItem.getState() &&am;' statusBarItem.getState()) { this.getContentPane().add(BorderLayout.NORTH, toolBar); this.getContentPane().add(BorderLayout.CENTER, splitPane); this.getContentPane().add(BorderLayout.SOUTH, statusLabel); } else if (toolBarItem.getState() && !statusBarItem.getState()) { this.getContentPane().add(BorderLayout.NORTH, toolBar); this.getContentPane().remove(statusLabel); } else if (statusBarItem.getState() && !toolBarItem.getState()) { this.getContentPane().add(BorderLayout.SOUTH, statusLabel); this.getContentPane().remove(toolBar); } else if (!toolBarItem.getState() && !statusBarItem.getState()) { this.getContentPane().remove(toolBar); this.getContentPane().remove(statusLabel); } this.show(); //添加或移去组件后刷新界面 } |