Pio*_*otr 4 java swing netbeans
这是我的简单应用程序:
public class MainFrame extends JFrame{
private Dimension size;
private JPanel buttonPanel;
private JButton button;
public MainFrame() throws ClassNotFoundException{
super("Applikacja1");
try {
UIManager.setLookAndFeel("com.formdev.flatlaf.FlatDarkLaf");
} catch (Exception ex) {
}
JFrame.setDefaultLookAndFeelDecorated(true);
size = new Dimension(350, 530);
setPreferredSize(size);
setMinimumSize(size);
setLocationRelativeTo(null);
setLayout(new BorderLayout());
pack();
//setting button
button = new JButton("Start programu");
button.setVisible(true);
this.add(button);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
}
}
Run Code Online (Sandbox Code Playgroud)

我需要做什么才能将该程序的外观更改为 FlatLaf 并使用他们的库?我需要从互联网下载什么?我尝试下载整个代码(从这里https://www.formdev.com/flatlaf/),然后将其作为库添加到 netbeans 中,但它不起作用。有人可以做一个完全新手的教程吗?
I am not an expert on this, but here are some instructions:
You can download and install the following files:
All the files I mentioned so far can be found where the site guides you to find them, for example the latest release files of your desired library can be found all together here. You can find this link as follows: first navigate to the FlatLaf's home page, then scroll a bit down on this page to find the section Download which gives you another link, the one in the Maven repository (specifically this one). There you can find instructions on how to link the library to your project and, of course, download the necessary files. In this case, there are two buttons on the top right, the one called Browse and the other called Downloads. The Downloads button simply drops down a list of all assets (ie files) that you can download. The Browse button navigates you to the directory of the server where you can find all the files presented with the drop down list of the Downloads button, so let's go there in order to see all the available files...
If you went there, you can see many more files. Most of them are imporant for security, which something I did not cover yet. It is always important to verify the integrity of the files you download, because there are security risks if you don't. You don't want the library you download to be a malicious copy provided by a phising site for example. So you need to verify them together with the link you are visiting. Admitedly, I am not doing this very often, when downloading libraries, but I feel that, my neglectness of doing it, does not make it something I should not mention. So I am warning you: be aware of what you are downloading.
Let's have a break to see what all those files (most likely) are:
Best way to verify the integrity in my opinion is to simply download the source code, verify it yourself and via the provided resources, then build form source (if you trust your compiler) and install. But that's not so simple, nor time preserving. All those links I provide may contain malicious content: I just cannot know yet because I haven't spent the necessary time to verify. So continue at your own risk, as they usually say. Also note I am getting a warning when downloading jar files generally because "they are not trusted" as the message says. Moving on...
If you have a system to automate the building process of your project (instead of compiling each and every Java source code file of your project with javac command line utility), such as Apache Maven, Gradle, Apache Ant and others, then you have the option to include a so called dependecy of the library in your project and let the build system synchronize (ie download and include the library in the build process). This is at least what happens with Gradle which I am a little familiar with. As for the others I am not really familiar, so this is where I stop talking for them. Just note that there are several instructions and tutorials and documentation about how to use them, either via command line directly, or via your IDE. Then the library developers as far as I know usually they let you know how to include the corresponding dependency in the build tool's settings file.
You can download the source code (of this software at least) from GitHub, or sometimes by FTP sites or generally from some online server of some sort which provides the corresponding content, and build it. The source code of your desired library is located here, as you have probably found out, judging from the question.
So now that you downloaded (and verified), or built what you needed, the actual installation is as follows... I am going to demonstrate for the NetBeans 8.2 IDE with Java 8 (the minimum supported version for FlatLaf), but the steps I guess are generally the same for each IDE and version. If they are not, you can be more specific about your environment and then we can talk again.
您可以查阅GitHub页面,或指导您完成的项目主页。基本上你可以尝试以下方法:
import com.formdev.flatlaf.FlatDarkLaf;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class Main {
private static void createAndShowGUI() {
FlatDarkLaf.setup(); //Must be called first of all Swing code as this sets the look and feel to FlatDark.
final JPanel panel = new JPanel(); //FlowLayout.
panel.add(new JButton("FlatDarkLaf button!"));
panel.add(new JTextField("FlatDarkLaf text field!"));
final JFrame frame = new JFrame("FlatDarkLaf test.");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(final String[] args) {
SwingUtilities.invokeLater(Main::createAndShowGUI);
}
}
Run Code Online (Sandbox Code Playgroud)
最后注意:您必须在创建任何 Swing 组件之前应用 LAF。在您问题中的代码中,您似乎不是,因为您首先创建JFrame(通过构造函数的super调用),然后以也不推荐的方式安装 LAF。
| 归档时间: |
|
| 查看次数: |
8966 次 |
| 最近记录: |