0

I got this error when I try to call a JDialog from ActionListener,I tried several solution but it didnt work the code here is for the JDialog class:

    package Ex2;
import java.awt.BorderLayout;

import javax.swing.BoxLayout;


import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class dialog extends JDialog {

    private JTextField f1;
    private JTextField f2;
    private JLabel label0;
    private JLabel label1;
    private JLabel label2;
    private JCheckBox check;
    private ButtonPanel buttons;

    public dialog() {
        setTitle("title");

        this.setLayout(new BorderLayout());

        JPanel pNorth = new JPanel();
        JPanel pCenter2 = new JPanel();
        JPanel pCenter3 = new JPanel();

        label0 = new JLabel("entrer le texte a rechercher");
        pNorth.add(label0);
        add(pNorth,BorderLayout.NORTH);

        JPanel pCentre = new JPanel();

        setLayout(new BoxLayout(pCentre,BoxLayout.X_AXIS));
        JPanel pCenter1 = new JPanel();

        setLayout(new BoxLayout(pCenter1,BoxLayout.Y_AXIS));
        buttons = new ButtonPanel(4, 'y');

        pCenter1.add(buttons);

        f1=new JTextField(30);
        f2=new JTextField(30);

        setLayout(new BoxLayout(pCenter2,BoxLayout.Y_AXIS));

        pCenter2.add(f1);
        pCenter2.add(f2);

        label1=new JLabel("Rechercher: ");
        label2=new JLabel("Remplacer par: ");

        setLayout(new BoxLayout(pCenter3, BoxLayout.Y_AXIS));
        pCenter3.add(label1);
        pCenter3.add(label2);

        pCentre.add(pCenter1);
        pCentre.add(pCenter2);
        pCentre.add(pCenter3);

        add(pCentre,BorderLayout.CENTER);

        setSize(100,100);
        setVisible(true);
    }}

the ActionListener class wich call the JDialog

 package Ex2;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;

import javax.swing.SwingUtilities;

public class actionListener implements ActionListener{


    public void actionPerformed(ActionEvent e) {

                new dialog();

    }


}

the test class is JFrame wich when click the button 3 should call the event

    package Ex2;

import javax.swing.JFrame;

public class test extends JFrame{
    public test(){
        setTitle("title");

        ButtonPanel a = new ButtonPanel(5, 'y');
        a.setAction(3, new actionListener());
        add(a);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(200,200);
        setVisible(true);
    }

    public static void main(String args []){
        new test();
    }

}
TheGreenGoblen
  • 108
  • 1
  • 11
  • I checked This http://stackoverflow.com/questions/761341/boxlayout-cant-be-shared-error and this http://stackoverflow.com/questions/5917017/java-awt-awterror-boxlayout-cant-be-shared but I didnt find a solution – TheGreenGoblen Jan 12 '15 at 01:56
  • `setLayout(new BoxLayout(pCentre,BoxLayout.X_AXIS));` is apply the `BoxLayout` to `dialog`, but it's been setup for `pCentre`??? – MadProgrammer Jan 12 '15 at 01:58
  • I did not understand ? – TheGreenGoblen Jan 12 '15 at 02:02
  • Yes,I want to apply it to pCentre – TheGreenGoblen Jan 12 '15 at 02:03
  • 1
    Then set it to pCentre: `pCentre.setLayout(new BoxLayout(pCentre,BoxLayout.X_AXIS));`. You've neglected to prepend the `pCentre.` portion. You must call `setLayout(...)` on the component whose layout is actually being set. Makes sense when you think about it, doesn't it? – Hovercraft Full Of Eels Jan 12 '15 at 02:11

0 Answers0