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

        Java Swing - 如何在另一个面板上显示一个面板?

        时间:2023-09-29
          <tbody id='2Zksl'></tbody>
            <bdo id='2Zksl'></bdo><ul id='2Zksl'></ul>

            • <tfoot id='2Zksl'></tfoot>
              <legend id='2Zksl'><style id='2Zksl'><dir id='2Zksl'><q id='2Zksl'></q></dir></style></legend>

                  <small id='2Zksl'></small><noframes id='2Zksl'>

                  <i id='2Zksl'><tr id='2Zksl'><dt id='2Zksl'><q id='2Zksl'><span id='2Zksl'><b id='2Zksl'><form id='2Zksl'><ins id='2Zksl'></ins><ul id='2Zksl'></ul><sub id='2Zksl'></sub></form><legend id='2Zksl'></legend><bdo id='2Zksl'><pre id='2Zksl'><center id='2Zksl'></center></pre></bdo></b><th id='2Zksl'></th></span></q></dt></tr></i><div id='2Zksl'><tfoot id='2Zksl'></tfoot><dl id='2Zksl'><fieldset id='2Zksl'></fieldset></dl></div>
                  本文介绍了Java Swing - 如何在另一个面板上显示一个面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我希望有一个内部(非窗口)对话框来询问成员输入.我希望将对话框集中放置在现有的 JPanel 上.

                  我查看了

                  编辑

                  分层窗格不合适的原因是由于缺少每层的布局管理器.面板可调整大小,面板 A 应保持在 100% 的区域,面板 B 应保持集中.

                  解决方案

                  我认为 LayeredPane 是你最好的选择.您将需要第三个面板来包含 A 和 B.这第三个面板将是 layeredPane,然后面板 A 和 B 仍然可以有一个不错的 LayoutManagers.您所要做的就是使 B 居中于 A 之上,在 Swing 路径中​​有很多关于如何做到这一点的示例.不使用 LayoutManager 的定位教程.

                  公共类 Main {私有 JFrame 框架 = new JFrame();私人 JLayeredPane lpane = new JLayeredPane();私人JPanel panelBlue = new JPanel();私人JPanel panelGreen = new JPanel();公共主要(){frame.setPreferredSize(新维度(600, 400));frame.setLayout(new BorderLayout());frame.add(lpane, BorderLayout.CENTER);lpane.setBounds(0, 0, 600, 400);panelBlue.setBackground(Color.BLUE);panelBlue.setBounds(0, 0, 600, 400);panelBlue.setOpaque(true);panelGreen.setBackground(Color.GREEN);panelGreen.setBounds(200, 100, 100, 100);panelGreen.setOpaque(true);lpane.add(panelBlue, new Integer(0), 0);lpane.add(panelGreen, new Integer(1), 0);框架.pack();frame.setVisible(true);}/*** @param args 命令行参数*/公共静态无效主要(字符串[]参数){新的主要();}}

                  您可以使用 setBounds 将面板定位在分层窗格内并设置它们的大小.

                  编辑以反映对原始帖子的更改您将需要添加组件侦听器,以检测何时调整父容器的大小,然后动态更改面板 A 和 B 的边界.

                  I wish to have an internal (non window) dialog to ask for member input. I would like the dialog to be placed centrally on an existing JPanel.

                  I have looked at layeredpanes and these seem unusable due to only having a single layout manager (or no layout manager) across all the panes. I guess I could try to override JLayeredPane and provide a custom layout but this seems extreme.

                  Glass panes don't seem to be appropriate either.

                  How can this be done? Is there no usable concept of z-indexes in Swing?

                  EDIT

                  The reason Layered Panes weren't appropriate was due to the lack of a layout manager per layer. The panel is resizeable, Panel A should stay at 100% of area and Panel B should stay centralized.

                  解决方案

                  I think LayeredPane is your best bet here. You would need a third panel though to contain A and B. This third panel would be the layeredPane and then panel A and B could still have a nice LayoutManagers. All you would have to do is center B over A and there is quite a lot of examples in the Swing trail on how to do this. Tutorial for positioning without a LayoutManager.

                  public class Main {
                      private JFrame frame = new JFrame();
                      private JLayeredPane lpane = new JLayeredPane();
                      private JPanel panelBlue = new JPanel();
                      private JPanel panelGreen = new JPanel();
                      public Main()
                      {
                          frame.setPreferredSize(new Dimension(600, 400));
                          frame.setLayout(new BorderLayout());
                          frame.add(lpane, BorderLayout.CENTER);
                          lpane.setBounds(0, 0, 600, 400);
                          panelBlue.setBackground(Color.BLUE);
                          panelBlue.setBounds(0, 0, 600, 400);
                          panelBlue.setOpaque(true);
                          panelGreen.setBackground(Color.GREEN);
                          panelGreen.setBounds(200, 100, 100, 100);
                          panelGreen.setOpaque(true);
                          lpane.add(panelBlue, new Integer(0), 0);
                          lpane.add(panelGreen, new Integer(1), 0);
                          frame.pack();
                          frame.setVisible(true);
                      }
                  
                  
                      /**
                       * @param args the command line arguments
                       */
                      public static void main(String[] args) {
                          new Main();
                      }
                  
                  }
                  

                  You use setBounds to position the panels inside the layered pane and also to set their sizes.

                  Edit to reflect changes to original post You will need to add component listeners that detect when the parent container is being resized and then dynamically change the bounds of panel A and B.

                  这篇关于Java Swing - 如何在另一个面板上显示一个面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Lucene 搜索结果按自定义订单列表排序(每个用户唯 下一篇:Java - 全局的、可重用的加载对话框

                  相关文章

                  最新文章

                  <tfoot id='pnN55'></tfoot>

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

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