简体   繁体   English

如何在初始化+ Netbeans设计视图上隐藏JFrame的组件:彩色显示

[英]How to hide components of a JFrame on initialization + Netbeans design view: color display

I'm using the design view of Netbeans to create a UI for my Java App. 我正在使用Netbeans的设计视图为Java应用程序创建UI。 For my login window I want the label "Wrong username..." to show up ONLY if the login wasn't successful. 对于我的登录窗口,我只希望在登录失败后才显示“ Wrong username ...”标签。

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(!tryLogin()) jLabel3.setVisible(true);
} 

So what's a best-practice to hide the label at the beginning? 那么在开始时隐藏标签的最佳实践是什么?

Where should I put jLabel3.setVisible(false); 我应该在哪里放置jLabel3.setVisible(false); ?

And since this is probably an extremely easy question I got one more problem: 由于这可能是一个非常简单的问题,所以我又遇到了一个问题:

I set the background color of my JFrame to a different one that is displayed in the Netbeans design view. 我将JFrame的背景色设置为NetBeans设计视图中显示的另一种颜色。 What can I do for it to display all my color changes immediatly? 我要怎么做才能立即显示所有颜色变化? I saw a possible answer here: Netbeans GUI preview is different from Runtime view but I cannot find "%APPDATA%\\CompanyName\\myApp\\mainFrame.session.xml" to test it and not sure if it will solve my problem. 我在这里看到了可能的答案: Netbeans GUI预览与“运行时”视图不同,但是我找不到“%APPDATA%\\ CompanyName \\ myApp \\ mainFrame.session.xml”来对其进行测试,不确定是否可以解决我的问题。

Here are the pics of the UI in design view and when it's actually running: 以下是设计视图中的UI图片以及何时实际运行: 在此处输入图片说明 在此处输入图片说明

if you need more information just let me know! 如果您需要更多信息,请告诉我!

any other tips for UI making are greatly appreciated :D 用户界面制作的任何其他技巧都非常感激:D

  • Set jLabel3.setVisible(false); 设置jLabel3.setVisible(false); in the constructor. 在构造函数中。

  • set your button opaque, using jbutton.setOpaque(true) or from Netbeans properties tab select the checkbox against the property "Opaque". 使用jbutton.setOpaque(true)将按钮设置为不透明,或者从Netbeans属性选项卡中选中属性“ Opaque”的复选框。

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

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