Netbeans Platform's TopComponents are functionally similar to JFrames in many ways, and are intended to be used so, besides the fact that TopComponent
extends JComponent
.
However, I'm currently trying to use Docking Frames for my application. I would like to insert a bunch of these in one of my TopComponents, but the control class expects a JFrame as a parameter, and it cannot be instantiated without it. As I said, TopComponent
doesn't extend JFrame
, so I can't simply cast them, but sadly, they would probably do the trick if I could.
What can I do?
Try using nested JPanel
instead.
GridBagLayout
. JPanel
. I use GridBagConstraints
because it's just one line method to ensure "full frame" layout. You can probably use any other layout to do the same. I try to keep TopComponent
as small as possible. All GUI components are in nested JPanels
. When you want to test your code without NetBeans platform you'd just add parent JFrame
instead of TopComponent
.
public MyTopComponent() {
initComponents();
panel = new MyPanel();
//ensures that our panel will be using 100% of our TopComponent
add(panel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
GridBagConstraints.NORTHWEST,
GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0)
);
}
//this code is generated by GUI editor
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setLayout(new java.awt.GridBagLayout());
}// </editor-fold>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.