- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
来自 Netbeans 的 Matisse 代码已被阻止。我遇到的问题是,我必须从不同包中的另一个类将 setBackground
设置为 JLabel
,但我无法执行此操作,因为我无法访问 JLabel
由于其私有(private)且被阻止的代码。
有什么办法可以解决这个问题吗?
最佳答案
"The Matisse code from Netbeans is blocked"
您可以编辑它,如图 here
"because i have no access to the JLabel due to its private and blocked code"
只需为另一个类中的标签编写一个getter
方法
public class OtherClass .. {
private JLabel jLabel1;
public JLabel getLabel() {
return jLabel1;
}
}
import otherpackage.OtherClass;
public class MainFrame extends JFrame {
private OtherClass otherClass;
...
private void jButtonActionPerformed(ActionEvent e) {
JLabel label = otherClass.getLabel();
label.setBackground(...)
}
}
<小时/>
"Access jframe component from another class"
听起来您正在使用多个框架。请参阅The Use of Multiple JFrames, Good/Bad Practice?
<小时/>更新
" I have a MAIN frame made in matisse but due to some reasons i have to set the background of an textField inside matisse from another class when X validation happens in the other class"
然后您可以做的是将 Main
框架的引用传递给另一个类,并在 Main
框架中拥有一个 setter
。比如(我会提供一个访问的接口(interface))
public interface Gettable {
public void setLabelBackground(Color color);
}
public class Main extends JFrame implements Gettable {
private JLabel jLabel1;
private OtherPanel otherPanel;
public void initComponents() {
otherPanel = new OtherPanel(Main.this); // see link above to edit this area
}
@Override
public void setLabelBackground(Color color) {
jLabel1.setBackground(color);
}
}
public class OtherPanel extends JPanel {
private Gettable gettable;
public OtherPanel(Gettable gettable) {
this.gettable = gettable;
}
private void jButtonActionPerformed(ActionEvent e) {
gettable.setLabelBackground(Color.RED);
}
}
关于java - NetBeans Matisse - 从另一个类访问 jframe 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23006570/
我是JAVA桌面应用程序开发的新手,最初开始创建默认包下的所有类。后来我了解到这不是一个好的做法,所以我根据类的功能将它们移动到不同的包中。作为此转变的一部分,我通过重构将 GUI 类与两个自定义 J
我创建了一个自定义的 JButton,其中覆盖了 setIcon。 public class TestButton extends JButton { public TestButton()
在 NetBeans 中使用 Matisse 时,有没有办法改变组件的类型?我想将标准 JDesktopPane 切换到我自己的扩展版本。谢谢! 最佳答案 Java 中独立应用程序的所有可视组件均基于
我想创建一个 GUI,其中一些文本字段可以水平调整大小,但也指定了最大宽度。例如,首选宽度为 100 像素,如果调整窗口大小可以更大,但最大允许宽度为 200 像素。 GroupLayout支持这个,
来自 Netbeans 的 Matisse 代码已被阻止。我遇到的问题是,我必须从不同包中的另一个类将 setBackground 设置为 JLabel,但我无法执行此操作,因为我无法访问 JLabe
有没有办法仅使用 GUI 在 JCombobox Netbeans Swing Matisse 中设置键值字符串映射/对?下面的屏幕截图允许插入单个列表 但是有没有办法使用 Matisse GUI 而
我决定在 Netbeans GUI 构建器(又名 Matisse)中更改组件的布局。 现在它完全搞砸了我的面板。我想在中心添加一个主面板(即默认),然后在左侧或右侧添加其他组件,但是在 Netbean
UPD:解决了! 美好的一天! 我开始在 netbeans 6.9.1 中开发 JAVA GUI 应用程序(我使用 matisse)。所以我决定在我的程序中实现 windowListener 但我遇到
关于这些 GUI 开发插件中哪一个更好的任何评论。 我已经在 NetBeans 上尝试过马蒂斯,我确实喜欢它。 是WindowBuilderPro (我还没有尝试过)比马蒂斯更好的选择? 最佳答案 W
默认情况下,Netbeans 会将所有拖放组件创建到单个类文件中。 我使用的是带有 3 个选项卡的 JPanel。我想将每个选项卡分离为 Netbeans Matisse 中的一个单独的类。有没有这样
我创建了一个带有属性(getter/setter)的自定义 ValueObject 类,我需要这个类来对表单上的元素进行数据绑定(bind)。所以我想将它拖到 matisse 编辑器上的“其他组件”,
我编写了一个 swing 库,并将其与 matisse 一起使用到我的项目中。 现在我想做一些名称包装更改,一个非常简单的操作,但问题是重构无法触及matisse编写的代码(锁定编辑)。 所以问题是:
在 Eclipse/SWT 或 Netbeans/Matisse 之间,Java GUI 编辑器在快速开发和可维护性方面为您提供了什么? 最佳答案 您实际上是在问两个不同的问题:SWT 与 Swing
在回答之前:是的,我已经阅读了 Sun 的 jtable 教程。不,这对我没有帮助。是的,我是个傻瓜。 请不要在回答时提及该文档。我特别感兴趣的是如何通过 Netbeans IDE 动态地将行和列添加
尝试在 NetBeans GUI 设计工具中打开自定义 JPanel 类时,出现以下错误: 警告 - 表单加载时出现错误 加载组件属性时出错:[JPanel]->someScrollPane->som
我是一名优秀的程序员,十分优秀!