Reputation: 17
I have created a JDialog
which has components (JLabel
s, JButton
s, JTextField
s, etc), and I have another JDialog
apart from that, that I want to have some of the components to the first JDialog
, so in the second JDialog
I've tried to add the components using .add()
method, but there is a mistake when I run the program....
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException
at org.netbeans.lib.awtextra.AbsoluteLayout.addLayoutComponent(Unknown
Source)
at java.awt.Container.addImpl(Container.java:1127)
at java.awt.Container.add(Container.java:1005)
at javax.swing.JDialog.addImpl(JDialog.java:921)
at java.awt.Container.add(Container.java:417)
at mainJFrame.initComponents(mainJFrame.java:721)
at mainJFrame.<init>(mainJFrame.java:30)
at mainJFrame.lambda$main$0(mainJFrame.java:1980)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
I will put a part of the code, specifically the part where I receive the error.
private void initComponents() {
practiceModeConfig = new javax.swing.JDialog(this);
//Here it supossed to go the declarations of the swings components
//(JLabels, Buttons,...) everything here is correct, so i dont
// want to put on here....
practiceModeConfig.setUndecorated(true);
practiceModeConfig.setDefaultCloseOperation(
javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
practiceModeConfig.setBackground(new java.awt.Color(242, 176, 53));
practiceModeConfig.setBounds(new java.awt.Rectangle(444, 308, 0,
0));
practiceModeConfig.setSize(new java.awt.Dimension(400, 300));
practiceModeConfig.getContentPane().setLayout(new
org.netbeans.lib.awtextra.AbsoluteLayout());
//This is a JSlider that i want to add in the next JDialog
practiceModeConfig.getContentPane().add(Slider, new
org.netbeans.lib.awtextra.AbsoluteConstraints(50, 410, 250, -1));
//And this is the other JDialog....
testModeConfig = new javax.swing.JDialog(this);
testModeConfig.setUndecorated(true);
testModeConfig.getContentPane().setLayout(new
org.netbeans.lib.awtextra.AbsoluteLayout());
testModeConfig.setDefaultCloseOperation(
javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
testModeConfig.setBackground(new java.awt.Color(242, 176, 53));
testModeConfig.setBounds(new java.awt.Rectangle(444, 308, 0,
0));
I want to do this with the JSlider
component from the first JDialog
, but I've received the mentioned error....
testModeConfig.getContentPane().add(Slider, new
org.netbeans.lib.awtextra.AbsoluteConstraints(50, 410, 250, -1));
Upvotes: 0
Views: 1579
Reputation: 324147
org.netbeans.lib.awtextra.AbsoluteConstraints(50, 410, 250, -1));
I would guess the "-1", would be a problem.
I don't use AbsoluteLayout, but I would think that value should represent the "height" of the component.
In any case you can read the API for the AbsoluteConstraints class to find out what that parameters should be.
My real suggestion is don't use AbsoluteLayout, or the form generator of your IDE. Swing was designed to be used with layout managers, so you should be creating your forms with the layout manager (or layout managers) the will do the layout based on your requirements.
Read the section from the Swing tutorial on Layout Managers for more information and working examples to get you started.
Upvotes: 1