Java Importing org-jdesktop-layout in Netbeans

久未见 提交于 2019-12-21 17:34:52

问题


I have added the org-jdesktop-layout.jar to my libraries in my netbeans in my project. I found this .jar file in: C:\Program Files\NetBeans 7.0.1\platform\modules

However the following line of code is still not recognized:

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());

I think I am missing the right import statement. What is the right import statement? If there is any other information that would be useful, let me know! Also what determines the prefix for an import statement?

EDIT: The following code seems to be from an older GUI library. I have two options, convert to newer GUI standards or access old GUI standards? I have never done anything like this before. What can I do?

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jButton1)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1)
                            .add(jLabel2))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(capFormattedTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(wtFormattedTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

I think this might be an older library... Thanks in advance


回答1:


You have to import the library class you want,

import org.jdesktop.layout.GroupLayout;

but you also have to right-click on the project's Libaries node, choose Add Library… and select Swing Layout Extensions. It should already be there waiting.



来源:https://stackoverflow.com/questions/14094566/java-importing-org-jdesktop-layout-in-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!