简体   繁体   English

Firefox选项窗格Java Swing中的UX设计?

[英]Firefox option pane UX design in Java Swing?

I need to design a window similar to Firefox > tools > options (shown below) using Java Swing. 我需要使用Java Swing设计类似于Firefox > tools > options (如下所示)的窗口。 I have to create two top headers. 我必须创建两个顶部标题。 On click of each I have to open tabbedpanes (Same as Firefox > tools > options > advanced . I am pretty much new to Swing. 每次单击时,我都必须打开选项卡式窗格(与Firefox > tools > options > advanced 。)Swing几乎是我的新手。

在此处输入图片说明

Thanks for the quick reply.I have tried implementing the same. 感谢您的快速回复。我已尝试实施相同的方法。 The base window is JDialog. 基本窗口是JDialog。 Whithin which I ahve created the top panel.The toolbar(at the BorderLayout-North of topPanel) and the content panel (at the BorderLayout-Center of topPanel) are added into this top panel. 我已经创建了顶部面板的Whithin。工具栏(位于topPanel的BorderLayout-North)和内容面板(位于topPanel的BorderLayout-Center)被添加到此顶部面板。 Two toolbar buttons-"general" and "advanced" are created which are the headers i was talking to in my last post."contentPanel" is the placeholder panel. 创建了两个工具栏按钮-“常规”和“高级”,它们是我上一篇文章中正在讨论的标题。“ contentPanel”是占位符面板。 where I want to dynamically add the tabbed panels whenever the toolbar butons gets clicked.And default is general. 我想在每当单击工具栏按钮时动态添加选项卡式面板的位置。默认为常规。

Whenevr the advanced toolbar button is clicked ,I want to remove the _generalTabbedPane and show the _advanceTabbedPane and vice versa. 当单击高级工具栏按钮时,我要删除_generalTabbedPane并显示_advanceTabbedPane,反之亦然。

But it is not happening properly.Adding and removing/hiding the panels when toolbar button is clicked is what I need to fix.I have attached the code below. 但是它没有正确发生。单击工具栏按钮时添加和删除/隐藏面板是我需要解决的问题。我已在下面附加了代码。

Kindly help. 请帮助。

 @Override
   public JComponent createContentPanel()
  {        
   topPanel  = new JPanel();
   topPanel.setLayout(new BorderLayout());     
   JToolBar toolBar = new JToolBar();
   toolBar.add(new tabButton("general",GENERAL));
   toolBar.add(new tabButton("advanced",ADVANCED));

   contentPanel = new JPanel();       
   contentPanel.add(getGeneralTabs());

   topPanel.add(toolBar, BorderLayout.NORTH);
   topPanel.add(contentPanel, BorderLayout.CENTER);        
   return topPanel;


}  
private  final class JCenterLabel extends JLabel
{       
    public JCenterLabel(final String s)
    {
        super(s);
        setAlignmentX(Component.CENTER_ALIGNMENT);
    }

    public JCenterLabel(final Icon i)
    {
        super(i);
        setAlignmentX(Component.CENTER_ALIGNMENT);
    }
}

private  class tabButton extends JButton
{   
    public tabButton (  String tabId,String actionCommand)
    {
        super();
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));      
        add(new JCenterLabel(UIManager.getIcon("OptionPane.informationIcon"))); 
        add(new JCenterLabel(tabId)); 
        this.setActionCommand(actionCommand);
        this.setName(tabId);
        this.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) { 
            String cmd = e.getActionCommand();
            if (GENERAL.equals(cmd)) { 
                if(contentPanel != null){
                contentPanel.remove(_advanceTabbedPane);     
                contentPanel.add(getGeneralTabs());
                contentPanel.revalidate();
                contentPanel.repaint();


                }

            } else if (ADVANCED.equals(cmd)) { 
                if(contentPanel != null){
                contentPanel.remove(_generalTabbedPane);               
                contentPanel.add(getAdvancedTabs());
                contentPanel.revalidate();
                contentPanel.repaint();


                }
            } 

        }
        });
}
}

  private JideTabbedPane  getGeneralTabs(){
    _generalTabbedPane = new JideTabbedPane();
    _generalTabbedPane.setModel(new TabbedPaneWithValidationModel());
    //adding the tabs to the _generalTabbedPane
    //-----
    //---

    return _generalTabbedPane;


}
  private   JideTabbedPane getAdvancedTabs(){
      _advanceTabbedPane = new JideTabbedPane();
      _advanceTabbedPane.setModel(new TabbedPaneWithValidationModel());
      //adding the tabs to the _advanceTabbedPane
    //-----
    //---
      return _advanceTabbedPane;

  }

I see a JToolBar in BorderLayout.NORTH , a JTabbedPane in BorderLayout.CENTER and a JPanel using FlowLayout.RIGHT in BorderLayout.SOUTH . 我看到一个JToolBarBorderLayout.NORTH ,一个JTabbedPaneBorderLayout.CENTERJPanel使用FlowLayout.RIGHTBorderLayout.SOUTH BorderFactory can supply the titled border. BorderFactory可以提供标题的边框。

Addendum: I have to create two top headers. 附录: 我必须创建两个顶部标题。

If you need two top headers, you can add two instances of JToolBar to a JPanel having GridLayout(0, 1) , then add that panel to BorderLayout.NORTH . 如果需要两个顶部标题,则可以将两个JToolBar实例添加到具有GridLayout(0, 1)JPanel中,然后将该面板添加到BorderLayout.NORTH See also this nested panel example . 另请参见此嵌套面板示例 Use Action to encapsulate your toolbar behaviors, for example . 使用Action封装工具栏的行为, 例如

Addendum: Whenever the advanced toolbar button is clicked, I want to remove the generalTabbedPane and show the advanceTabbedPane and vice versa. 附录: 每当单击高级工具栏按钮时,我都想删除 generalTabbedPane 并显示 advanceTabbedPane ,反之亦然。

You could use CardLayout , shown here , to accomplish this. 可以使用此处显示的CardLayout来完成此任务。 A better approach might be to let each tab's abstract parent implement a suitable interface method , eg setAdvanced() . 更好的方法可能是让每个选项卡的抽象父级实现合适的接口方法 ,例如setAdvanced() The default would do nothing, but some concrete implementations could respond accordingly. 默认值不会执行任何操作,但是某些具体的实现可能会做出相应的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM