简体   繁体   English

如何使用 JTextField、JButton 和 JLabel 构建带有图形区域paintComponent 的 JFrame 窗口?

[英]how to build a JFrame window with a graphic area paintComponent with JTextField, JButton and JLabel?

I've been searching in google how to build something that looks like in the image.我一直在谷歌搜索如何构建图像中看起来像的东西。 Text boxes, labels, buttons with actions and a graphic area all in one JFrame, but I only can find them separated.文本框、标签、带有操作的按钮和图形区域都在一个 JFrame 中,但我只能发现它们是分开的。 I mean, I understand how to build them separated but no how to put them together.我的意思是,我知道如何将它们分开构建,但不知道如何将它们组合在一起。 I've been reading about using GridBagConstraints but is very confusing.我一直在阅读有关使用 GridBagConstraints 的信息,但非常令人困惑。 I would appreciate any tip.我将不胜感激任何提示。

图像描述简介

The easiest way is to use the BorderLayout and include your panels ("separated components") at the regions (north, south, east, west, or center) you want.最简单的方法是使用BorderLayout并在您想要的区域(北、南、东、西或中心)包含您的面板(“分离的组件”)。

    JFrame frame = new JFrame();

    JPanel actions = new JPanel();
    JPanel graph = new JPanel();

    frame.setLayout(new BorderLayout());
    frame.getContentPane().add(actions, BorderLayout.SOUTH);
    frame.getContentPane().add(graph, BorderLayout.CENTER);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM