How can I convert an Icon to an Image

Just found a code snippet which might help if you want to wrap those misbehaving LAF provided icons more often: /** * Some ui-icons misbehave in that they unconditionally class-cast to the * component type they are mostly painted on. Consequently they blow up if * we are trying to paint them anywhere else (f.i. … Read more

How to set a transparent background of JPanel?

Calling setOpaque(false) on the upper JPanel should work. From your comment, it sounds like Swing painting may be broken somewhere – First – you probably wanted to override paintComponent() rather than paint() in whatever component you have paint() overridden in. Second – when you do override paintComponent(), you’ll first want to call super.paintComponent() first to … Read more

Adding a Scrollable JTextArea (Java)

It doesn’t work because you didn’t attach the ScrollPane to the JFrame. Also, you don’t need 2 JScrollPanes: JFrame frame = new JFrame (“Test”); JTextArea textArea = new JTextArea (“Test”); JScrollPane scroll = new JScrollPane (textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); frame.add(scroll); frame.setVisible (true);

How to align left or right inside GridBagLayout cell?

When using GridBagLayout for a tabular display of JLabel : JTextField, I like to have a method that makes my GridBagConstraints for me based on the x, y position. For example something like so: private GridBagConstraints createGbc(int x, int y) { GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = 1; … Read more

Integrating JavaFX 2.0 WebView into a Swing Java SE 6 Application

It is very well possible! One has to install JavaFX 2.0, and somehow manage to have jfxrt.jar in the Classpath. The following code renders a JFXPanel inside a JFrame. The JFXPanel contains a WebView which loads google.com. However, at least on my machine, the WebView feels rather sloppy. I’m working on Mac OS X 10.6; … Read more

Java 8 poor GUI performance compared to Java 6

According to my profiler, the operation spends most of the time in the method Thread.holdsLock, which can be indeed a costly operation, which is called by Component.checkTreeLock which is called indirectly by Component.updateCursorImmediately. Generally, you can avoid costly visual updates when updating multiple components by calling getContentPane().setVisible(false); right before the operation and getContentPane().setVisible(true); right afterwards, … Read more

tech