The WindowBuilder is broken I can't add some of the components. When I try to do it:
Here is the error message
And when I try to add the component
Widow Builder was not able to show the GUI.
java.lang.NullPointerException
at org.eclipse.wb.internal.swing.java6.model.SwingVisualMapper.getComponentPreferredSize(SwingVisualMapper.java:85)
at org.netbeans.modules.form.layoutdesign.LayoutDesigner.endMoving(LayoutDesigner.java:596)
at org.eclipse.wb.internal.layout.group.model.GroupLayoutSupport.command_create(GroupLayoutSupport.java:277)
at org.eclipse.wb.internal.layout.group.gef.GroupLayoutEditPolicy2$4.executeEdit(GroupLayoutEditPolicy2.java:510)
at org.eclipse.wb.core.gef.command.EditCommand$1.run(EditCommand.java:52)
at org.eclipse.wb.internal.core.utils.execution.ExecutionUtils.run(ExecutionUtils.java:324)
at org.eclipse.wb.core.gef.command.EditCommand.execute(EditCommand.java:50)
at org.eclipse.wb.internal.gef.core.EditDomain.executeCommand(EditDomain.java:59)
at org.eclipse.wb.gef.core.tools.Tool.executeCommand(Tool.java:209)
I tried to add it manually and it worked.
The other problem is when I try to add any component, it creates it and after the creation Window Builder stuck. To fix it I have to return back to the source code wait 1-2 minutes. And I have to do this every time after I add new component.
This happens when I try to add a JLabel
I don't know if these bugs are because of Linux or it's just something wrong in my java/eclipse configuration. Are there any solutions?
Related
So, I am creating a GUI interface for the project via Netbeans (using it is a requirement). Everything is fine until I add an Icon for a label. The generated code is below:
jLabel25 = new javax.swing.JLabel();
jLabel25.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/mycompany/sostarnyba/images/map.png")));
jLabel25.setText("");
I add the icon exactly as the person in this question shows it: Netbeans ImageIcon not displaying
Except my app does not run at all.
When the icon is removed, everything runs, but when it is added it does not. The error is: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because "location" is null.
What am I doing wrong?
The problem was solved by putting not a full path within the project but the absolute path in your computer starting from /Users
I've been running into a problem lately where I try to se a JMenuItems icon which when I define and point to the icon the application it self don't start/show.
I started looking for errors, but there where none; started looking for write occurencies, which typically pretty much does appear when I add the icon and after that as pointed above the application doesn't start/show.
When the icon is set but commented:
Code
mntmMaximize = new JMenuItem();
mntmMaximize.setText("Maximize Window");
mntmMaximize.setActionCommand("maximize");
mntmMaximize.addActionListener(this);
mntmMaximize.setMnemonic(KeyEvent.VK_PLUS);
mntmMaximize.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, ActionEvent.CTRL_MASK));
// mntmMaximize.setIcon(new ImageIcon(Vision.class.getResource("xray/fullscreen16x.png")));
mnWindow.add(mntmMaximize);<br>
Picture:
Screen Shot Of Visible Application
After the icon is set and trying to execute application:
Code:
mntmMaximize = new JMenuItem();
mntmMaximize.setText("Maximize Window");
mntmMaximize.setActionCommand("maximize");
mntmMaximize.addActionListener(this);
mntmMaximize.setMnemonic(KeyEvent.VK_PLUS);
mntmMaximize.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, ActionEvent.CTRL_MASK));
mntmMaximize.setIcon(new ImageIcon(Vision.class.getResource("xray/fullscreen16x.png")));
mnWindow.add(mntmMaximize);<br>
Picture:
The window not created and application terminated
Note that when the window is not created in this picture the application is therefor terminated.
Please try to answer nice, and if you need the whole source file it is possible.
Edit:
Also if needed i can make a video where i show when i start the application when the icon is set but not commented.
getResource uses the relative path with respect to the package (folder), like in
Vision.class.getResource("fullscreen16x.png")
or absolute like in:
Vision.class.getResource("/xray/fullscreen16x.png")
I'm trying to add proper support for OS X in my Java 8 Swing application. To do this I'm using the com.apple:AppleJavaExtensions:1.4 package from maven.
I initialise the menu bar using the following code:
Application application = Application.getApplication();
JMenu fileMenu = new JMenu("File");
JMenuItem openMenuItem = new JMenuItem("Open...");
openMenuItem.addActionListener(action -> openFileDialog());
openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.META_MASK));
fileMenu.add(openMenuItem);
JMenuBar mainMenuBar = new JMenuBar();
mainMenuBar.add(fileMenu);
application.setDefaultMenuBar(mainMenuBar);
This works just fine the first time, without any Swing windows opened. However, when one file is opened (and a Swing window is created), the shortcut stops working. Pressing CMD+O still highlights the menu item, but the action isn't executed. Using the mouse to select the 'Open...' menu item does work. I'm guessing the Swing window is somehow stealing the event (but the menu is still highlighted when the key combo is pressed.. weird).
When the file open dialog (that openFileDialog() shows) is cancelled, the menu accelerator will keep working. So it is definitely related to the Swing window being opened when a file is opened.
Another problem with opening files with OS X is that the following code never shows 'foo':
application.setOpenFileHandler(e -> System.out.println("foo"));
This code is executed in main() (which returns almost instantly, after creating the menu bar I mentioned earlier). The file handler isn't ever called; not when dropping a file onto the dock icon, nor when double clicking a file and opening it with my application.
What am I doing wrong?
If your app doesn't have many Frames then this could be a workaround.
setJMenuBar(menuBar);
final Dimension invisible = new Dimension(0, 0);
menuBar.setSize(invisible);
menuBar.setMaximumSize(invisible);
menuBar.setPreferredSize(invisible);
menuBar.setMinimumSize(invisible);
Apparently the OpenFileHandler does nothing unless your Java application is running from an application bundle with an Info.plist that specifies appropriate CFBundleDocumentTypes. Here's an example of what it should look like:
http://www.qtcentre.org/wiki/index.php?title=Opening_documents_in_the_Mac_OS_X_Finder
I worked around the menu accelerator not working by simply registering a KeyEventDispatcher to the KeyboardFocusManager on each of the Swing windows, and manually invoking the appropriate ActionListeners when the correct KeyEvent is caught. Very very ugly, but it works. I'm still wondering why this is necessary.
I am using the jxbrowser from teamdev.
I found a little flaw on downloading items, it will always pop up a blank window with jxbrowser popup as title which break down the user experience here.
Attempt 1:
I try to override the download handler class without any popup code. It does not work.
Attempt 2:
I also try to override the popup handler that disable popup. It disable all the popup universally and it is not what I want. Plus, it return abstract method error.
browser.setPopupHandler(new PopupHandler() {
public PopupContainer handlePopup(PopupParams params) {
return new PopupContainer() {......}
does anyone familiar with jxbrowser? I would like to talk you.
I will setup a bounty shortly.
That depends your JxBrowser version but on JxBrowser 4 (Chromium) you can handle a download with the DownloadHandler by adding a DownloadListener and invoke a JFileChooser (Swing component) for example.
I am showing and hiding Eclipse view with code below. It works perfectly with Eclipse 3.3, but with Eclipse Juno (version 4.3) it's not showing the first time but showing when I fire the event for the second time.
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
page.showView(UserView.ID);
page.hideView(page.findView(UserView.ID));
Is somebody come across with this situation before?
I am not sure why you are not getting it the first time. Check to see if you dont have null pointer errors when you fire it the first time.
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
can return a null if the workbench is not yet loaded.
I faced the same issue with the minimized state, so I tried chaging the view's state forcing it to appear after page.showView(UserView.ID);
this piece of code got my viewPart to show :
page.showView(UserView.ID);
IWorkbenchPartReference ref = page.getReference(searchResultUI);
page.setPartState(ref,IWorkbenchPage.STATE_RESTORED); //or STATE_MAXIMIZED