- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在代码中执行以下调用:
...
setLayout(null);
...
我试图通过指定按钮和文本字段的 x 和 y 坐标来放置按钮和文本字段。
运行程序(使用 Eclipse 或 BlueJ)时的问题是,我需要在面板上运行到按钮和文本字段的位置,以便分别查看按钮和文本字段。
当我找到文本字段时,它很小。仅当我开始编写时,它才会采用我指定的大小。
有谁知道怎么解决吗?
最佳答案
避免 setLayout (null),除非你有充分的理由。您可以在这里了解布局管理器:http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html
如果您仍想使用空布局,则必须设置组件的宽度和高度,而不仅仅是其 x 和 y 位置(请参阅 setSize 方法)。
来自上述链接:
Although we strongly recommend that you use layout managers, you can perform layout without them. By setting a container's layout property to null, you make the container use no layout manager. With this strategy, called absolute positioning, you must specify the size and position of every component within that container. One drawback of absolute positioning is that it does not adjust well when the top-level container is resized. It also does not adjust well to differences between users and systems, such as different font sizes and locales.
关于java - 使用 "setlayout(null)"时小部件行为异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12308764/
运行实例化此类的代码时: static final class MyFrame extends JFrame { private CardLayout layout = new CardLay
我最近开始与Qt和Qwt合作。我一个人找不到我的错误。请帮我。有代码。 我知道我在这里某处的错误: .h文件 ... class MainWindow : public QMainWind
我无法在 EditorPane 上添加滚动条。 private JEditorPane editorPane; private JScrollPane scrollpane; 容器: Containe
我正在尝试编译这个非常简单的 BoxLayout 管理器测试,但我不断收到此错误:“Container 类型中的方法 setLayout(LayoutManager) 不适用于我的行面板上的参数 (L
我有代码 import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Graphics; import java.awt
我在代码中执行以下调用: ... setLayout(null); ... 我试图通过指定按钮和文本字段的 x 和 y 坐标来放置按钮和文本字段。 运行程序(使用 Eclipse 或 BlueJ)时的
我正在尝试构建一个小型垄断游戏。在这里您可以看到我遇到问题的代码部分。 public class Board extends JPanel { private ImageIcon image;
大多数布局管理器都有无参数构造函数(也就是说,您可以使用 new FlowLayout() 创建 FlowLayout,使用 new GridLayout() 创建 GridLayout,使用 Gri
public void frame_pizza() { pizzaMenu.setVisible(true); //makes Jframe pizzaMenu visible
我尝试将 JFrame 的背景颜色设置为红色,同时将 JPanel 保留白色。但它不能与 setLayout 一起工作 private void buildGraphics(){ JF
import javax.swing.*; import java.awt.*; class MenuPanel extends JPanel { JButton setTextColor;
执行时(没有编译错误)我进入控制台 QWidget::setLayout: Attempting to set QLayout "" on CGSearchResult "", which alrea
我正在尝试通过函数 setLayout 设置小部件的布局,但我收到错误消息: main.obj:-1: error: LNK2019: unresolved external symbol "publ
我将 JLabel 和我自己的 Panels 类添加到 JFrame 中。顺便说一下,我创建的 Panels 类继承自 JPanel。 我的代码仅显示两个组件之一:JLabel 或JPanel 继承类
有人知道为什么组合框没有显示吗?我有一个 Controller : public class TestController extends JPanel { TestView cgView; publ
我创建了一个 JPanel 并向其中添加了一个 JTabbedPane。然后我向该选项卡 Pane 添加了另外两个面板,并将所有面板的布局设置为 null。但框架不显示任何内容,如果我将主面板的布局从
我注意到当在 UICollectionView 中调用 setLayout:animated 以在两个布局之间切换时,当前可见的单元格不符合 zIndex 它的布局属性已在 layoutAttribu
本文整理了Java中com.tc.admin.common.XContainer.setLayout()方法的一些代码示例,展示了XContainer.setLayout()的具体用法。这些代码示例主
运行聊天应用程序时,我不断收到此错误: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.l
我想学习如何在没有设计器的情况下手工创建图形用户界面。我试图向我的 MainWindow 添加布局,但在运行时显示 QWidget::setLayout: Attempting to set QLay
我是一名优秀的程序员,十分优秀!