BoxLayout是一个Java Swing布局管理器,允许垂直或水平布局多个组件。
我正在开发一个客户端-服务器聊天应用程序,我试图在其中创建像 WhatsApp 中那样的语音气泡 我想在框架右侧显示已发送的消息和已接收的消息
我正在尝试为我的侄女制作一个简单的刽子手游戏(并练习一点 kivymd)。我输入了典型的起始代码,但屏幕上没有添加任何内容。 .py 文件是: 从 kivymd.app 导入 M...
如何在 Swing 中制作剧透(以及为什么简单的解决方案不起作用)
我正在尝试在 Swing 中制作剧透效果(就像 HTML 中的 / 标签)。但是,如果我切换 setVisible() 方法,我的父容器的高度不会正确计算... 我试图在 Swing 中制作剧透效果(就像 HTML 中的 <summary>/<details> 标签)。但是,如果我切换 setVisible() 方法,我的父容器的高度将无法正确计算。 我尝试显示和隐藏的面板的所有父容器都使用 BoxLayout 和页面轴。 这是我的代码: public class Entry extends javax.swing.JPanel { public Entry() { initComponents(); } public Entry(Node node) { this.node = node; initComponents(); initEvents(); } private void initEvents() { marker.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (!opened) open(); else close(); } @Override public void mousePressed(MouseEvent e) {} @Override public void mouseReleased(MouseEvent e) {} @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseExited(MouseEvent e) {} }); addMouseListener(listener); } public void addChild(Entry child, int pos) { content.add(child, pos); //content.validate(); } public void inflate(int width) { if (node == null) return; if (node.nodeType == 1) { boolean isPaired = !TagLibrary.tags.containsKey(node.tagName.toLowerCase()) || TagLibrary.tags.get(node.tagName.toLowerCase()); if (!isPaired) { headerTag.setText("<" + node.tagName.toLowerCase()); headerTag2.setText(" />"); threeDots.setText(""); headerTag3.setText(""); content.setVisible(false); footer.setVisible(false); marker.setVisible(false); } else { headerTag.setText("<" + node.tagName.toLowerCase()); headerTag2.setText(">"); headerTag3.setText("</" + node.tagName.toLowerCase() + ">"); footerTag.setText("</" + node.tagName.toLowerCase() + ">"); } int w = Math.max(Math.max(header.getMinimumSize().width, min_width), width - margin); content.removeAll(); //System.out.println(getWidth()); for (int i = 0; i < node.children.size(); i++) { Entry e = new Entry(node.children.get(i)); content.add(e); e.inflate(w); } content.doLayout(); if (node.children.size() > 0) { open(); } else { close(); } } else if (node.nodeType == 3 && !node.nodeValue.matches("\\s*")) { content.removeAll(); header.setVisible(false); footer.setVisible(false); JTextArea textarea = new JTextArea(); textarea.setText(node.nodeValue); textarea.setEditable(false); textarea.setOpaque(false); textarea.setBackground(new Color(255, 255, 255, 0)); textarea.setColumns(180); textarea.setFont(new Font("Tahoma", Font.PLAIN, 16)); int rows = node.nodeValue.split("\n").length; textarea.setRows(rows); textarea.addMouseListener(listener); int height = getFontMetrics(textarea.getFont()).getHeight() * rows; content.add(textarea); content.setOpaque(false); int w = Math.max(Math.max(header.getMinimumSize().width, min_width), width - margin); header.setMinimumSize(new Dimension(w, line_height)); footer.setMinimumSize(new Dimension(w, line_height)); content.setPreferredSize(new Dimension(w, content.getPreferredSize().height)); ((JPanel)getParent()).setMinimumSize(new Dimension(w, line_height * 2 + content.getPreferredSize().height)); opened = true; content.validate(); } else { setVisible(false); content.removeAll(); opened = false; return; } int w = Math.max(Math.max(Math.max(content.getMinimumSize().width, header.getMinimumSize().width), min_width), width - margin); header.setMinimumSize(new Dimension(w, line_height)); footer.setMinimumSize(new Dimension(w, line_height)); content.setPreferredSize(new Dimension(w, content.getPreferredSize().height)); int height = line_height * 2 + content.getPreferredSize().height; if (opened) { setSize(w, height); } } public void setWidth(int width) { int w = Math.max(Math.max(header.getMinimumSize().width, min_width), width - margin); setPreferredSize(new Dimension(w, getPreferredSize().height)); header.setMinimumSize(new Dimension(w, line_height)); footer.setMinimumSize(new Dimension(w, line_height)); content.setPreferredSize(new Dimension(w, content.getPreferredSize().height)); Component[] c = content.getComponents(); for (int i = 0; i < c.length; i++) { if (c[i] instanceof Entry) { ((Entry)c[i]).setWidth(w); } else { c[i].setSize(w, c[i].getMaximumSize().height); c[i].setMaximumSize(new Dimension(w, c[i].getMaximumSize().height)); } } } public static final int min_width = 280; public static final int line_height = 26; public static final int margin = 30; MouseListener listener = new MouseListener() { @Override public void mouseClicked(MouseEvent e) {} @Override public void mousePressed(MouseEvent e) {} @Override public void mouseReleased(MouseEvent e) {} @Override public void mouseEntered(MouseEvent e) { updateChildren(true); repaint(); } @Override public void mouseExited(MouseEvent e) { updateChildren(false); repaint(); } }; private void updateChildren(boolean value) { hovered = value; Component[] c = content.getComponents(); for (int i = 0; i < c.length; i++) { if (c[i] instanceof Entry) { ((Entry)c[i]).updateChildren(value); } } } @Override public void paintComponent(Graphics g) { if (hovered) { g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(new Color(190, 230, 255, 93)); g.fillRect(0, 0, getWidth(), getHeight()); } else { g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(new Color(255, 255, 255)); g.fillRect(0, 0, getWidth(), getHeight()); } //super.paintComponent(g); } private boolean hovered = false; public void open() { marker.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/triangle.png"))); threeDots.setVisible(false); headerTag3.setVisible(false); content.setVisible(true); footer.setVisible(true); opened = true; //getParent().getParent().setPreferredSize(new Dimension(getParent().getPreferredSize().width, getParent().getPreferredSize().height + delta)); //getParent().getParent().setPreferredSize(new Dimension(getParent().getParent().getSize().width, getParent().getParent().getSize().height + delta)); //((JComponent)getParent()).validate(); } public void close() { marker.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/triangle2.png"))); content.setVisible(false); footer.setVisible(false); threeDots.setVisible(has_children); marker.setVisible(has_children); headerTag3.setVisible(true); opened = false; //getParent().setPreferredSize(new Dimension(getParent().getPreferredSize().width, getParent().getPreferredSize().height - delta)); //getParent().getParent().setPreferredSize(new Dimension(getParent().getParent().getSize().width, getParent().getParent().getSize().height - delta)); //((JComponent)getParent().getParent()).revalidate(); } public void openAll() { open(); Component[] c = content.getComponents(); for (int i = 0; i < c.length; i++) { if (c[i] instanceof Entry) { ((Entry) c[i]).openAll(); } } } public void closeAll() { close(); Component[] c = content.getComponents(); for (int i = 0; i < c.length; i++) { if (c[i] instanceof Entry) { ((Entry) c[i]).closeAll(); } } } public boolean opened = false; public Node node; @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { header = new javax.swing.JPanel(); headerMargin = new javax.swing.JPanel(); marker = new javax.swing.JLabel(); headerTag = new javax.swing.JLabel(); attributes = new javax.swing.JPanel(); headerTag2 = new javax.swing.JLabel(); threeDots = new javax.swing.JLabel(); headerTag3 = new javax.swing.JLabel(); content = new javax.swing.JPanel(); footer = new javax.swing.JPanel(); footerMargin = new javax.swing.JPanel(); footerTag = new javax.swing.JLabel(); setBackground(new java.awt.Color(255, 255, 255)); setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS)); header.setBackground(new java.awt.Color(255, 255, 255)); header.setAlignmentX(0.0F); header.setMaximumSize(new java.awt.Dimension(32767, 26)); header.setMinimumSize(new java.awt.Dimension(280, 26)); header.setOpaque(false); header.setPreferredSize(new java.awt.Dimension(280, 26)); header.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING, 0, 2)); headerMargin.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 0, 0, 5)); headerMargin.setMaximumSize(new java.awt.Dimension(30, 26)); headerMargin.setOpaque(false); headerMargin.setPreferredSize(new java.awt.Dimension(30, 26)); marker.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); marker.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/triangle.png"))); // NOI18N marker.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); marker.setPreferredSize(new java.awt.Dimension(22, 22)); javax.swing.GroupLayout headerMarginLayout = new javax.swing.GroupLayout(headerMargin); headerMargin.setLayout(headerMarginLayout); headerMarginLayout.setHorizontalGroup( headerMarginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(headerMarginLayout.createSequentialGroup() .addComponent(marker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); headerMarginLayout.setVerticalGroup( headerMarginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(headerMarginLayout.createSequentialGroup() .addComponent(marker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); header.add(headerMargin); headerTag.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N headerTag.setForeground(new java.awt.Color(102, 0, 153)); headerTag.setText("<body"); header.add(headerTag); attributes.setMaximumSize(new java.awt.Dimension(32767, 26)); attributes.setOpaque(false); attributes.setPreferredSize(new java.awt.Dimension(0, 26)); attributes.setLayout(new javax.swing.BoxLayout(attributes, javax.swing.BoxLayout.LINE_AXIS)); header.add(attributes); headerTag2.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N headerTag2.setForeground(new java.awt.Color(102, 0, 153)); headerTag2.setText(">"); header.add(headerTag2); threeDots.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); threeDots.setText("..."); threeDots.setPreferredSize(new java.awt.Dimension(19, 20)); header.add(threeDots); headerTag3.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N headerTag3.setForeground(new java.awt.Color(102, 0, 153)); headerTag3.setText("</body>"); header.add(headerTag3); add(header); content.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 30, 0, 0)); content.setAlignmentX(0.0F); content.setOpaque(false); content.setLayout(new javax.swing.BoxLayout(content, javax.swing.BoxLayout.PAGE_AXIS)); add(content); footer.setBackground(new java.awt.Color(255, 255, 255)); footer.setAlignmentX(0.0F); footer.setMaximumSize(new java.awt.Dimension(32767, 26)); footer.setOpaque(false); footer.setPreferredSize(new java.awt.Dimension(91, 26)); footer.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING, 0, 2)); footerMargin.setOpaque(false); footerMargin.setPreferredSize(new java.awt.Dimension(30, 26)); javax.swing.GroupLayout footerMarginLayout = new javax.swing.GroupLayout(footerMargin); footerMargin.setLayout(footerMarginLayout); footerMarginLayout.setHorizontalGroup( footerMarginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 30, Short.MAX_VALUE) ); footerMarginLayout.setVerticalGroup( footerMarginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 26, Short.MAX_VALUE) ); footer.add(footerMargin); footerTag.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N footerTag.setForeground(new java.awt.Color(102, 0, 153)); footerTag.setText("</body>"); footer.add(footerTag); add(footer); }// </editor-fold> // Variables declaration - do not modify private javax.swing.JPanel attributes; private javax.swing.JPanel content; private javax.swing.JPanel footer; private javax.swing.JPanel footerMargin; private javax.swing.JLabel footerTag; private javax.swing.JPanel header; private javax.swing.JPanel headerMargin; private javax.swing.JLabel headerTag; private javax.swing.JLabel headerTag2; private javax.swing.JLabel headerTag3; private javax.swing.JLabel marker; private javax.swing.JLabel threeDots; // End of variables declaration } public class Node { public Node() {} public Node(Node parent_node) { if (parent_node.nodeType == 1) { parent = parent_node; parent_node.addChild(this); } } public Node(int node_type) { nodeType = node_type; } public Node(Node parent_node, int node_type) { if (parent_node.nodeType == 1) { parent = parent_node; parent_node.addChild(this); } nodeType = node_type; } public boolean addChild(Node node) { if (nodeType == 1) { children.add(node); return true; } return false; } public Node parent; public Vector<Node> children = new Vector<Node>(); public LinkedHashMap<String, String> attributes = new LinkedHashMap<String, String>(); public Node previousSibling; public Node nextSibling; public String tagName = ""; public int nodeType = 3; public String nodeValue = ""; } public class TagLibrary { public static void init() { if (init) return; tags.put("br", false); tags.put("hr", false); tags.put("link", false); tags.put("img", false); tags.put("a", true); tags.put("span", true); tags.put("div", true); tags.put("p", true); tags.put("sub", true); tags.put("sup", true); tags.put("b", true); tags.put("i", true); tags.put("u", true); tags.put("s", true); tags.put("strong", true); tags.put("em", true); tags.put("quote", true); tags.put("cite", true); tags.put("table", true); tags.put("thead", true); tags.put("tbody", true); tags.put("cite", true); tags.put("head", true); tags.put("body", true); leaves.add("style"); leaves.add("script"); init = true; } private static boolean init = false; public static Hashtable<String, Boolean> tags = new Hashtable<String, Boolean>(); public static Vector<String> leaves = new Vector<String>(); } 主要课程: public class WebInspectorTest { private static Node prepareTree() { Node root = new Node(1); root.tagName = "body"; Node p = new Node(root, 1); p.tagName = "p"; Node text1 = new Node(p, 3); text1.nodeValue = "This is a "; Node i = new Node(p, 1); i.tagName = "i"; Node text2 = new Node(i, 3); text2.nodeValue = "paragraph"; return root; } public static void main(String[] args) { try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) {} final Node root = prepareTree(); if (root == null) return; final JFrame frame = new JFrame("Document Inspector"); JPanel cp = new JPanel(); cp.setBorder(BorderFactory.createEmptyBorder(9, 10, 9, 10)); frame.setContentPane(cp); cp.setLayout(new BorderLayout()); final JPanel contentpane = new JPanel(); contentpane.setBackground(Color.WHITE); contentpane.setOpaque(true); final int width = 490, height = 418; final JScrollPane scrollpane = new JScrollPane(contentpane); scrollpane.setOpaque(false); scrollpane.getInsets(); cp.add(scrollpane); scrollpane.setBackground(Color.WHITE); scrollpane.setOpaque(true); scrollpane.setPreferredSize(new Dimension(width, height)); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { TagLibrary.init(); final Entry rootEntry = new Entry(root); contentpane.add(rootEntry); final JScrollPane sp = scrollpane; int width = sp.getVerticalScrollBar().isVisible() ? sp.getWidth() - sp.getVerticalScrollBar().getPreferredSize().width - 12 : sp.getWidth() + sp.getVerticalScrollBar().getPreferredSize().width; rootEntry.inflate(width); contentpane.addComponentListener(new java.awt.event.ComponentAdapter() { @Override public void componentMoved(java.awt.event.ComponentEvent evt) {} @Override public void componentResized(java.awt.event.ComponentEvent evt) { int width = sp.getVerticalScrollBar().isVisible() ? sp.getWidth() - sp.getVerticalScrollBar().getPreferredSize().width - 12 : sp.getWidth() - 12; rootEntry.setWidth(width); } }); } }); } } 这里出了什么问题?我尝试直接设置直接父级的新大小,但这对这种情况没有帮助。 给父母打电话revalidate()也不会改变任何事情。 要查看效果,您可以单击任何文本行中第一个字母左侧的三角形(我无法在此处附加图像文件,triangle和triangle2是小10x10实心填充蓝色三角形的两个副本分别向下和向右看)。 如果您尝试关闭根目录,它将无法再正确打开。另外,根关闭后,它会移动到父级 JScrollPane 的中心。 更新: 这是更新后的代码,似乎解决了“从根部跳到中心”问题并解决了一般的最小化/最大化行为。但是, <i> 元素在切换时仍然会跳跃。 public void open() { marker.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/triangle.png"))); threeDots.setVisible(false); headerTag3.setVisible(false); content.setVisible(true); footer.setVisible(true); opened = true; int w = Math.max(Math.max(content.getMinimumSize().width, header.getMinimumSize().width), min_width); int height = opened ? line_height * 2 + content.getPreferredSize().height : line_height; if (content.getMinimumSize().height > content.getPreferredSize().height) { content.setPreferredSize(content.getMinimumSize()); } setSize(w, height); setPreferredSize(null); } public void close() { int delta = line_height + content.getPreferredSize().height; marker.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/triangle2.png"))); content.setVisible(false); footer.setVisible(false); boolean has_children = node.children.size() > 0; threeDots.setVisible(has_children); marker.setVisible(has_children); headerTag3.setVisible(true); opened = false; int w = Math.max(getParent().getSize().width, Math.max(Math.max(content.getMinimumSize().width, header.getMinimumSize().width), min_width)); int height = opened ? line_height * 2 + content.getPreferredSize().height : line_height; setSize(w, height); if (getParent().getParent() instanceof Entry) { getParent().setSize(new Dimension(getParent().getPreferredSize().width, getParent().getPreferredSize().height - delta)); } else { setPreferredSize(new Dimension(w, height)); } } 更新2:似乎“根条目居中”问题可以通过另一种方式解决:我可以将JScrollPane内根面板的布局管理器设置为null。它还修复了在调整大小处理程序方法中进行奇怪操作的需要,在该方法中,我从新宽度中减去凭经验发现的 12 数字,以在不需要时保持滚动。 但是,中间的切换元素上的跳跃仍然存在。 更新3:我编写了自己的非常简单的布局管理器,但它仍然无法正常工作。事实上,它的效果甚至比BoxLayout还要糟糕。我不明白,为什么。 import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Insets; import java.awt.LayoutManager; public class LinearLayout implements LayoutManager { public LinearLayout() { this(X_AXIS); } public LinearLayout(int direction) { this.direction = direction; } public LinearLayout(int direction, int gap) { this.direction = direction; this.gap = gap; } @Override public void addLayoutComponent(String name, Component comp) {} @Override public void removeLayoutComponent(Component comp) {} @Override public Dimension preferredLayoutSize(Container parent) { int width = 0; int height = 0; Insets insets = parent.getInsets(); Component[] c = parent.getComponents(); if (direction == X_AXIS) { for (int i = 0; i < c.length; i++) { if (c[i].getSize().height > height) { height = c[i].getSize().height; } width += c[i].getSize().width + gap; } } else { for (int i = 0; i < c.length; i++) { if (c[i].getSize().width > width) { width = c[i].getSize().width; } height += c[i].getSize().height + gap; } } width += insets.left + insets.right; height += insets.top + insets.bottom; return new Dimension(width, height); } @Override public Dimension minimumLayoutSize(Container parent) { return preferredLayoutSize(parent); } @Override public void layoutContainer(Container parent) { Dimension dim = preferredLayoutSize(parent); Component[] c = parent.getComponents(); Insets insets = parent.getInsets(); int x = insets.left; int y = insets.top; for (int i = 0; i < c.length; i++) { if (direction == X_AXIS) { c[i].setBounds(x, y, c[i].getSize().width, dim.height); x += c[i].getSize().width + gap; } else { c[i].setBounds(x, y, dim.width, c[i].getSize().height); y += c[i].getSize().height + gap; } } } private int direction = 0; private int gap = 0; public static final int X_AXIS = 0; public static final int Y_AXIS = 1; } 看来,正如评论中的人们所说,我应该定义自己的大小调整方法(getPreferredSize/getMinimumSize/getMaximumSize)实现。我为我的一些面板实现了它们,问题得到了解决。
我可以在 JLayeredPane 上使用 BoxLayout 来单独分隔每层上的项目吗?
我正在创建 Uno 作为我的 CompSci 课程中的期末项目。 playerHandPanel 中的卡片由 JButton 组成。按钮应该按照处理的顺序依次显示,但也...
使用 JPanel 的 Y_AXIS 约束将 JLabel 与 BoxLayout 内的左或右对齐
我有一个带有 Y_Axis 约束的 JPanel,这样每当我添加新组件时,它都会自动添加到新行上。但问题是里面的标签没有左对齐或 Ri 对齐...
我在使用 BoxLayout 创建嵌套面板时遇到问题。我有一个布局设置为 BoxLayout (PAGE_AXIS) 的容器,在这个容器中我想生成面板 (postedPanel) 也...
为什么我的 JButton 大小没有通过 setSize() 或 setPreferredSize() 改变?
我正在为学校项目制作一个基本计算器,我需要满足的要求之一是更改 JPanel 内 JButton 的大小。我已经尝试过这样做,但它没有改变......
我无法将按钮放置在 kivymd 的中心,我首先尝试使用正常的框布局,然后尝试两个按钮,但它们仍然相互连接,(我尝试插入两个标签,它们是
如何在使用 Kivy 创建窗口时同时使用 BoxLayout 和 Screen
我是 Kivy 编程的新手,正在尝试制作菜单和菜单遍历系统。但是我在 BoxLayout 和 Screen 功能之间有冲突,想知道可以做什么......
如何在 JavaSwing 的框布局中设置文本字段的首选大小
代码 我使用 JFrames 在 netbeans 中创建了一个 GUI。我在设计中使用了盒子布局,但我无法根据自己的喜好设置名为“loca”的 Jtextfield 的大小。 出...
如何将JLabels和Jpanels在BoxLayout中向左对齐?
我想在一个垂直的BoxLayout中把标签和一个面板(包含按钮)向左对齐。只要我不将面板添加到BoxLayout中,所有的东西都能完美地向左对齐,但是......我想将标签和一个面板(包含按钮)在一个垂直的BoxLayout中向左对齐。
我有一个自定义面板(APanel)。两个问题:我需要标签(“顶部标签”)和子面板(bPanel)在面板的左侧对齐。 bPanel在左侧对齐,但“顶部标签”为...
添加到BorderLayout时无法在JPanel中左对齐JLabel
这似乎很简单,但是我无法使其正常工作。我有一个BorderLayout。我想将顶部用作标题栏。我想添加带有标签,按钮和其他组件的JPanel。 ...
我正在尝试为我的应用程序(学校项目)创建注册表单,我想将布局设置为BoxLayout,但是Jtextfields和组合框出现问题,如下所示。
我有一个非常简单的自定义组件。它的首选最大尺寸为100x100,只是一个红色矩形。我将其添加到使用框布局的JPanel中。我会...
我在使用BoxLayout时遇到问题。在我的示例中,我尝试减小文本字段的高度并更改按钮的宽度(如底部图片中的绿色标记所示)。我...
我想使用2个JPanel作为面板和panel_1。我想使用JLabel将图像自动添加到面板,并且还要将JButton添加到panel_1。如何根据...
我正在尝试将浮动版式放置在Boxlayout内。当我尝试此操作时,内部的标签会相互堆叠。我究竟做错了什么?谢谢!来自kivy.app导入来自kivy.uix.boxlayout ...
我正在尝试使用BoxLayout将JPanel的内容垂直居中。 BoxLayout与Y轴对齐,因此内部的项目水平对齐。例如,我现在拥有的是----------------...
我使用Kivy创建了嵌套的框布局,该布局有效。但是我需要在我的Python代码中调用三个类。有没有更优雅的方式做到这一点?例如。在Python中只有一堂课? ...