java Swing 中的锚定和停靠控件

编程入门 行业动态 更新时间:2024-10-25 14:31:13
本文介绍了java Swing 中的锚定和停靠控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 中有一个称为锚定的控件,用于随表单动态调整控件的大小.当控件锚定到窗体并调整窗体大小时,控件会保持控件与锚点位置之间的距离.

In there is a control called anchoring that is used to resize controls dynamically with the form. When a control is anchored to a form and the form is resized, the control maintains the distance between the control and the anchor positions.

我的问题是,Java 中是否有任何控件具有与 中的锚定功能相同的功能.例如,我选择了一个文本字段并将其放在面板上并正确调整其大小.现在,当我更改窗口(JFrame)的大小或最大化窗口时,文本字段将不会保持与以前相同的距离.我一直在使用 netbeans,但我没有在托盘管理器中找到任何可以回答我的问题的属性.请用一个例子或一些链接来解释我.

My question is that is there any controls in java that does same functionality as anchoring in . As for an example i have selected a textfield and put it on the panel and resized it properly. Now when i change the size of window(JFrame) or maximize the window the textfield will not maintain the same distance as it was previously. I have been using netbeans and i havent found any properties in pallete manager that answers my question. Please explain me with an example or some links.

推荐答案

Java Swing 使用布局管理器来管理可视组件的大小和位置.这是关于如何使用此布局管理器的官方 Java 教程:

Java Swing uses Layout Managers to manage the size and postion of visual components. This is the official java tutorial on how to use this Layout managers:

java.sun/docs/books/tutorial/uiswing/layout/using.html

还有最常见的布局管理器的简要说明

And there is a brief description of the most common layout managers

FlowLayout(默认):从左到右,从上到下布置组件.

FlowLayout (default): it disposes the components left to right and up to down.

BorderLayout:将容器划分为NORTH、SOUTH、WEST、EAST中心CENTER.按位置只有一个组件.边框上的组件展开,中心组件使用可用空间

BorderLayout: it divides the container in NORTH, SOUTH, WEST, EAST center CENTER. Only one component by position. Components on border expands and the center component uses the space avaiable

GridLayout:您初始化管理器,指示网格将有多少行和列.每个单元格的大小相同,您开始在左上角的单元格中添加组件.

GridLayout: you initialice the manager indicating how many rows and cols the grid is going to have. Each cell has same size and you start adding component on the top left cell.

GridBagLayout:最细粒度的布局管理器,你可以用它做任何事情,但有点复杂,请参阅 java 文档.

GridBagLayout: the MOST fine grained layout manager, you can do anything with this, but is a bit complicated, see the java documentation for it.

NullLayout(当您取消容器的布局管理器时):没有布局管理器,组件使用位置和大小属性显示在组件上.

NullLayout (when you nullify the container's layout manayer): no layout manager, components uses the location and size properties to show on components.

当然,其他容器中的容器可以使用与其父容器不同的布局管理器.结合布局管理器是一门难学的艺术.

And of course, containers inside in other containers can use a different layout manager than their parent. Combining layout managers is a difficult art to learn.

更多推荐

java Swing 中的锚定和停靠控件

本文发布于:2023-11-05 09:34:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560479.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   java   Swing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!