Skip to main content

JXLayer and Netbeans GUI builder (newbie question)

3 replies [Last post]
arwelbath
Offline
Joined: 2008-06-17
Points: 0

Hi,
Firstly, apologies for the 'newbie' question here, as I know this is a forum for hardcore Java developers (which I'm definately not!), but this is the only JXLayer forum I've found. So, sorry if I'm posting a dumb question (am quite new to Java).

I'd like to know if its possible to use JXLayer to lock a GUI made with Netbeans GUI builder? The problem I'm having is that the examples (e.g. locakbleDemo) make a JPanel with all the components in it, then wrap that with JXLayer. However, the GUI bulider makes the GUI by adding directly to the ContentPane, and it's not possible to edit that code. Is there a 'generic' way I can use for making my GUI's lockable?

Many thanks in advance,
Arwel

<br />
import javax.swing.JTabbedPane;<br />
import javax.swing.JButton;<br />
import java.awt.BorderLayout;<br />
import java.awt.Component;<br />
import javax.swing.JInternalFrame;<br />
import javax.swing.JButton;<br />
import javax.swing.JComponent;<br />
import javax.swing.JFrame;<br />
import javax.swing.JPanel;<br />
import java.awt.Container;<br />
import org.jdesktop.jxlayer.JXLayer;<br />
import org.jdesktop.jxlayer.plaf.ext.LockableUI;<br />
import org.jdesktop.jxlayer.plaf.effect.BufferedImageOpEffect;<br />
import com.jhlabs.image.BlurFilter;<br />
import java.lang.String;<br />
/**<br />
 *<br />
 * @author  Arwel<br />
 */<br />
public class mainEditGuiFrame extends JInternalFrame {</p>
<p>    private JXLayer layer;<br />
    private LockableUI blurUI = new LockableUI(new BufferedImageOpEffect(new BlurFilter()));</p>
<p>    /** Creates new form mainEditGuiFrame */<br />
    public mainEditGuiFrame() {<br />
        initComponents();<br />
        JComponent view = this.getContentPane();  // doesn't work!<br />
        layer = new JXLayer(view);<br />
        layer.setUI(blurUI);<br />
        add(layer);<br />
    }</p>
<p>    public JTabbedPane getPanel() {<br />
        return jTabbedPane1;<br />
    }</p>
<p>    public javax.swing.JButton getMainCancelButton() {<br />
        return mainCancelButton;<br />
    }</p>
<p>    public javax.swing.JButton getMainOKButton() {<br />
        return mainOKButton;<br />
    }</p>
<p>    public void setLocked() {<br />
        blurUI.setLocked(true);<br />
        repaint();<br />
    }</p>
<p>    public void setUnlocked() {<br />
        blurUI.setLocked(false);<br />
        repaint();<br />
    }</p>
<p>    /** This method is called from within the constructor to<br />
     * initialize the form.<br />
     * WARNING: Do NOT modify this code. The content of this method is<br />
     * always regenerated by the Form Editor.<br />
     */<br />
    //<br />
    private void initComponents() {<br />
        mainOKButton = new javax.swing.JButton();<br />
        mainCancelButton = new javax.swing.JButton();<br />
        jTabbedPane1 = new javax.swing.JTabbedPane();</p>
<p>        mainOKButton.setText("OK");</p>
<p>        mainCancelButton.setText("Cancel");</p>
<p>        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());<br />
        getContentPane().setLayout(layout);<br />
        layout.setHorizontalGroup(<br />
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)<br />
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()<br />
                .addContainerGap()<br />
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)<br />
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE)<br />
                    .add(layout.createSequentialGroup()<br />
                        .add(mainOKButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)<br />
                        .add(5, 5, 5)<br />
                        .add(mainCancelButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))<br />
                .addContainerGap())<br />
        );<br />
        layout.setVerticalGroup(<br />
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)<br />
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()<br />
                .addContainerGap()<br />
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)<br />
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)<br />
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)<br />
                    .add(mainCancelButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)<br />
                    .add(mainOKButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))<br />
                .addContainerGap())<br />
        );<br />
        pack();<br />
    }//                         </p>
<p>    // Variables declaration - do not modify<br />
    javax.swing.JTabbedPane jTabbedPane1;<br />
    javax.swing.JButton mainCancelButton;<br />
    javax.swing.JButton mainOKButton;<br />
    // End of variables declaration                   </p>
<p>}<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexfromsun
Offline
Joined: 2005-09-05
Points: 0

Hello Arwel

The generic way to make your component lockable is to wrap it with JXLayer

and set a LockableUI to it, and since JXLayer is not integrated to Netbeans,

you should write some code to make it happen

Here is a fix to your example:

(note that I also changed the parent class of the mainEditGuiFrame to JFrame)

[code]
public class mainEditGuiFrame extends JFrame {

private JXLayer layer;
private LockableUI blurUI = new LockableUI(new BufferedImageOpEffect(new BlurFilter()));

/** Creates new form mainEditGuiFrame */
public mainEditGuiFrame() {
initComponents();
JComponent view = (JComponent) this.getContentPane();
layer = new JXLayer(view, blurUI);
blurUI.setLocked(true);
layer.setUI(blurUI);
this.setContentPane((layer));
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new mainEditGuiFrame().setVisible(true);
}
});
}

// everything below is similar to your code
[/code]




I should say that wrapping the frame's content pane with JXLayer may be not the best idea

because after that frame.add() will not work as expected

the better way is to create an intermediate JPanel,

put all your components there and then add it to the frame as it is done in LockableDemo


Thanks

alexp

arwelbath
Offline
Joined: 2008-06-17
Points: 0

Hi Alex,
Thanks that works fine!.

Quote:
"I should say that wrapping the frame's content pane with JXLayer may be not the best idea
because after that frame.add() will not work as expected
the better way is to create an intermediate JPanel,
put all your components there and then add it to the frame as it is done in LockableDemo "

I suppose that's my whole point really. I looked at LockableDemo and saw how that is done, but the issue with using the Gui builder is that it makes the UI in its own section of code that is inaccessible.
The way around this I suppose would be to make a separate JPanel in GUI Builder, asve this to the pallette and then import this into another GUI which designs the overall frame...
But on the flipside, when using GUI builder one tends to design the whole GUI in it and so I suppose theres less reason to use frame.add() afterwards (because everything has been put in at the design stage).
But thanks very much for that.
Cheers,
Arwel

alexfromsun
Offline
Joined: 2005-09-05
Points: 0

Hello Arwel

You are welcome

I suppose you can mark this thread as "answered" now

;-)

Thanks

alexp