- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 swing 制作了一个 GUI,中间有一个 BorderLayout
和 GridLayout
。我想将我在另一个类中制作的三角形添加到我的 BorderLayout
中的 JPanel
东边,但无法显示它。
当我为 JPanel
设置一个 bgcolor
时,我得到了一个奇怪的小结果,如果你愿意,可以看看代码:gistlink
我感觉问题出在 TriGoButton
构造函数中,但我不确定如何进一步测试。我尝试了 paint()
的不同变体,但从未能够看到绿色三角形。
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@SuppressWarnings("serial")
public class TestGUI extends JFrame implements ActionListener {
private JPanel content;
private JTextField placeTxtField;
public static void main(String[] args) {
TestGUI frame = new TestGUI();
frame.pack();
frame.setVisible(true);
}
@SuppressWarnings("rawtypes")
public TestGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
content = new JPanel();
content.setLayout(new BorderLayout());
setContentPane(content);
// issue
JPanel rightPanel = new JPanel();
content.add(rightPanel, BorderLayout.EAST);
rightPanel.add(new TriGoButton());
// issue?
JPanel leftPanel = new JPanel();
content.add(leftPanel, BorderLayout.WEST);
JPanel centerPanel = new JPanel();
content.add(centerPanel, BorderLayout.CENTER);
centerPanel.setLayout(new GridLayout(3, 3, 0, 20));
JLabel countyLbl = new JLabel("County");
centerPanel.add(countyLbl);
JComboBox countyDropDown = new JComboBox();
centerPanel.add(countyDropDown);
JLabel muniLbl = new JLabel("Munipalicity");
centerPanel.add(muniLbl);
JComboBox muniDropDown = new JComboBox();
centerPanel.add(muniDropDown);
JLabel placeLbl = new JLabel("City or place");
placeLbl.setToolTipText("search");
centerPanel.add(placeLbl);
placeTxtField = new JTextField();
centerPanel.add(placeTxtField);
placeTxtField.setColumns(15);
placeTxtField.setToolTipText("enter w/e");
JPanel bottomPanel = new JPanel();
content.add(bottomPanel, BorderLayout.SOUTH);
JButton goBtn = new JButton("Clicky");
bottomPanel.add(goBtn);
goBtn.setToolTipText("Please click.");
goBtn.addActionListener(this);
JPanel topPanel = new JPanel();
content.add(topPanel, BorderLayout.NORTH);
JLabel headlineLbl = new JLabel("headline");
topPanel.add(headlineLbl);
}
@Override
public void actionPerformed(ActionEvent e) {
}
}
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class TriGoButton extends JPanel {
public TriGoButton() {
add(new JPanel(), BorderLayout.EAST);
setBackground(new Color(100,100,250)); //blue //wtf
}
public void paint(Graphics g) {
super.paint(g);
int[]x={90,90,300};
int[]y={150,0,90};
g.setColor(new Color(23,201,10)); //green
g.fillPolygon(x,y,3);
}
}
编辑:////////////
最佳答案
JPanel
添加到您的 TriGoButton
类中,但这会给您带来问题。paint
,这可能会导致无休止的问题,因为在绘制子容器时父容器并不总是包含在更新中。参见 Painting in AWT and Swing和 Performing Custom Painting了解更多详情。BorderLayout
将使用组件的 preferredSize
来决定它应该如何调整大小。您的 TriGoButton
类应该覆盖 getPreferredSize
方法并返回适当的默认大小..关于java - 在 BorderLayout 的 JPanel east 上显示图形三角形的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27095312/
我是山姆的新手。 我正在运行 aws-cli/2.1.37 Python/3.8.8 Darwin/19.6.0 exe/x86_64提示/关闭 SAM CLI,版本 1.29.0 请参阅下面的 te
我想上传一个文件到 amazon CLI 但它不工作 当我手动上传时它工作正常 我正在使用下面的命令 aws s3 cp /localfolderlocation awss3foldername --
我正在使用来自 http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-sample-templates.html 的美国东
我正在尝试 aws quicksight 入门教程: https://docs.aws.amazon.com/quicksight/latest/user/embedded-dashboards-wi
我如何训练 EAST text detector在我的自定义数据上。没有任何在线博客显示执行相同操作的分步过程。我目前拥有的。 我有一个文件夹,其中包含所有图像和每个图像对应的 xml 文件,这些文件
如果我在东侧或西侧添加像 JButton 这样的组件,我如何防止它紧贴屏幕的一侧?我想要在 JButton 和屏幕边缘之间留出一些空间。 最佳答案 像这样在您的 JButton 上调用 setBord
我希望我的多行标签右对齐...不知道为什么这这么困难。我尝试使用weightx并添加一个空白jlabel并赋予其权重1.0。我无法让它发挥作用。这个想法是一个人全部左对齐,另一个人右对齐。 (有点像短
我将对象动态添加到面板,然后添加到我的边框布局。我需要西部、中心和东部的大小都相等。这是我目前所拥有的: static int width = 300;//Screen width static in
是否有 clang 格式的标志将“const west”更改为“east const”,以便以下内容: void fun(const std::string &s); 将被重新格式化为: void f
我正在尝试用 Java 转换以下页面中的文本检测示例。原始代码在 C++ 中。 https://github.com/opencv/opencv/blob/master/samples/dnn/tex
应用程序是 Spring 3.1.0,具有 EJB 绑定(bind)和 WAS 7 部署。 尝试使用带有以下实现的resteasy-jaxrs和jaxrs-api jar来调用Rest Service
我使用 swing 制作了一个 GUI,中间有一个 BorderLayout 和 GridLayout。我想将我在另一个类中制作的三角形添加到我的 BorderLayout 中的 JPanel 东边,
我正在尝试使用 EAST 文本检测器来检测图像中的文本区域,但在加载预训练的 EAST 文本检测器时遇到了问题。 下面是我的text_detection.py文件 from imutils.objec
我正在寻找一个消息队列即服务,它...... .. 托管在 AWS us-east .. 提供真正的 PubSub(不是轮询!) ..可用于生产 .. 提供高可用性 .. 有一个很好的 Java 客户
我在本地训练 EAST 没有任何问题: https://github.com/foamliu/EAST 但问题是,我需要在云/Azure 机器学习上训练它,而我只能看到“笔记本”。有没有一种方法可以直
我正在使用 BorderLayout、3 个带有 GridLayout 的容器和 8 个 JLabel 的数组。 Container #1 使用 2 个 JLabel,Container #2 使用
我想制作一个带有 BorderLayout 的程序,其中中心和东部在图形上是分开的。我尝试了以下操作,但不幸的是分隔符位于 JFrame 的左侧,而不是在 centerPanel 和 rightPan
您好,我创建了一个枚举方向 public enum Direction { EAST, SOUTH, WEST, NORTH; } 在我的算法代码中,我无法在我的一个循环中调用 EAST
我有一个jqueryui可调整大小的div。我只希望宽度可以调整大小,高度保持自动,以便 div 随内容而增大或缩小。如果我将其设置为仅显示东 handle 并使用 css height:auto,则
我在网上找到的大多数例子都更喜欢 constexpr 的“西方风格” (C++11), consteval ,和constinit (C++20): consteval auto sqr(int n)
我是一名优秀的程序员,十分优秀!