- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
有两件事我想弄清楚。首先,我想弄清楚如何使 JComponent 背景透明。当将 JPanel 放入另一个设置了颜色作为背景的 JPanel 中时,在另一个 JPanel 中设置的 JPanel 具有我似乎无法摆脱的白色背景。我尝试使用firstpanel.setOpache函数并重新绘制,但它没有做任何事情。
其次,我注意到将一个 JPanel 放入另一个 JPanel 中(该 JPanel 又位于另一个 JPanel 中)会压缩其大小。下面的图片将显示我想要描述的内容。我想知道如何避免压缩 JPanel 大小并仍然能够将其放在其他 JPanel 的两个级别内。下面的代码是我正在练习的代码。
import javax.swing.*;
import java.awt.*;
public class LearningFrame extends JFrame {
private JLabel userLabel;
private LearningFrame(){
JPanel backGroundPanel = new JPanel();
JPanel mainPanel = new JPanel();
JPanel firstPanel = new JPanel();
JPanel secondPanel = new JPanel();
userLabel = new JLabel("User");
userLabel.setFont(new Font("Arial",1 ,24));
backGroundPanel.setBackground(new Color(247,211,53));
// backGroundPanel.setLayout(new BoxLayout(backGroundPanel,BoxLayout.Y_AXIS));
setContentPane(backGroundPanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1200,800);
setLocationRelativeTo(null);
//backGroundPanel.setLayout(null);
mainPanel.setLayout(new GridLayout(1,2));
firstPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
secondPanel.setLayout(new BoxLayout(secondPanel,BoxLayout.Y_AXIS));
// firstPanel.setBackground(new Color(211,43,185));
secondPanel.setBackground(new Color(34,233,44));
JButton button = new JButton("Click");
JButton button2 = new JButton("Click");
JButton button3 = new JButton("Click");
JButton button4 = new JButton("Click");
firstPanel.add(button);
firstPanel.add(button2);
firstPanel.add(userLabel);
secondPanel.add(button3);
secondPanel.add(button4);
mainPanel.add(firstPanel);
mainPanel.add(secondPanel);
backGroundPanel.add(mainPanel);
setVisible(true);
}
public JPanel logPanel() {
JPanel logInPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JTextField userTextField = new JTextField(14);
JTextField passTextField = new JTextField(14);
userLabel = new JLabel("Username: ");
JLabel passLabel = new JLabel("Password: ");
passLabel.setFont(new Font("Arial", Font.BOLD, 24));
userLabel.setFont(new Font("Arial", Font.BOLD, 24));
logInPanel.add(userLabel);
logInPanel.add(userTextField);
logInPanel.add(passLabel);
logInPanel.add(passTextField);
logInPanel.setOpaque(true);
logInPanel.repaint();
return logInPanel;
}
public static void main(String[] args){
LearningFrame x = new LearningFrame();
}
}
最佳答案
只需使用
firstPanel.setOpaque(false);
这将使组件的背景不可见,但您仍然可以看到位于其中的任何组件。
关于java - 如何让JComponents背景透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38257242/
这个问题已经有答案了: Mirroring an Object in JFrame with paintComponent (1 个回答) 已关闭 6 年前。 我已经知道 JComponent 无法添
我在绘制 jcomponent 时遇到问题 //应在其中绘制矩形的类 public class Board extends JComponent { private Case[][] case
在 Swing 中,鼠标事件会自动定位到具有鼠标监听器的最深组件。当有一个组件具有鼠标监听器并添加到其他组件之上时,如何将它们再次定位到更深的组件? 应该在不将组件设置为不可见或删除其鼠标监听器的情况
最近我在使用 Swing 时遇到了一些问题。我正在尝试快速制作下图所示的内容,以说明算法的数据结构。 (来源:ius.edu) 我在接下来的类(class)中尝试做的就是画出一些带有数字的矩形。并翻译
我已经阅读了 oracle 提供的 Java trail,他们说对象属性设置为与操作属性相匹配。我想知道这是否是一组有限的共享属性,或者是否将 Action 强制转换为与您将操作设置为的对象相同的类。
我有一个 JCombobox,我在运行时添加一些项目。其中一些非常长,我的 Jcombobox 也长得很长。它位于带有 BoxLayout (PAGE_AXIS) 的 JPanel 容器中。我不知道如
我正在处理一个项目,该项目要求我能够在同一容器内的组件顶部绘制半透明的 JPanel。使用 setComponentZOrder() 方法对于重叠(即下方的组件未完全覆盖)效果很好,但当下方的组件完全
目前,我必须将 JComponent 包含在具有垂直框布局的 JPanel 中。这样,我可以将第一个组件居中,如下所示,并将底部组件(相当长)放在下面。但是,由于底部组件非常长,我想仅为该特定组件添加
我有一个 JComponent 子类,我用它在屏幕上绘制形状。在构造函数中,我尝试将 ballX 和 ballY 设置为 X 和 Y 大小值的一半JComponent,我想我做错了。我现在已经查了很多
我想完成一些与带有选择器线的矩形图像非常相似的事情。 基本上,我有一个矩形,我想在它周围有一条选择器线。为此,我想创建一个额外的 JComponent。 目前我只能绘制矩形。如何在 Rectangle
到目前为止,我一直在使用 VB 来开发应用程序。现在我必须使用Java来开发前端。我对组件很困惑。需要帮助。书籍引用或网站引用也可以完成这项工作。 基本上,我将使用菜单栏、工具栏、带有 JEditor
我有一个自定义 JComponent,它在调用 paint 时绘制一些内容。但是,在 Border 布局中,它的 minimumSize 并未得到尊重。我已经包含了这个 @Override publi
我是一名初学者程序员,我正在尝试让这个程序运行。尽管 JComponent 的新 Java 屏幕上没有出现任何图像,但一切都可以正确编译。该程序要做的几乎就是获取一个输入值并将其分配给条形图的大小值。
我有以下代码: package gui; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; imp
如何获取JComponent名称(JComboBox,JCheckBox,JTextComponent...等) 我如何获取 fieldName 并将此名称放入 HashMap,例如:
我在面板上有一个 JTable 和一个 JLabel。我将其设置为背景图像,但无法摆脱表格和标签中的灰色背景。 我该怎么做? 最佳答案 尝试在 JTable 和 JLabel 上执行 .setOpaq
我正在尝试将组件添加到我的 JPanel,但是它们的大小不正确且位置不正确。这是我的组件代码。 button = new JButton(); button.setSize(100, 100); bu
好的。我正在编写我的 Ball 类,但球没有显示。我尝试将其他组件添加到我的容器中并且它们被显示,所以我认为可以安全地假设问题出在我的球上。类代码: import java.awt.Color; im
作为项目的一部分,我有一个自定义 JComponent,它实现了一部分用户界面。这是一个相当奇怪的控制,涉及围绕一组 x-y 点移动,但这并不重要,因为它已经实现并且工作正常。 该组件有一个正方形的可
嗨,我是java初学者,这里我有我的程序,但是,当我尝试调整面板大小时,我的文本就消失了?此外,如何在文本下绘制一条粗绿线,即使在调整大小时它也会保留在文本下方,我很无能? import javax.
我是一名优秀的程序员,十分优秀!