Home > Net >  Can't open swing window from jar
Can't open swing window from jar

Time:04-09

I'm writing a chat, using swing. I've built a jar from client's main, but it can't open window while it opens from intelij... How can I solve this problem?

This is my constructor of window class (I'm creating window in client's Main):

public MyWindow() {
        setBounds(600,300,600,500);
        setLocationRelativeTo(null);
        setTitle("Chat");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        Font chatFont = new Font("Arial", Font.BOLD, 12);

        chatArea = new JTextArea();
        chatArea.setEditable(false);
        chatArea.setFocusable(false);
        chatArea.setLineWrap(true);
        chatArea.setFont(chatFont);
        chatArea.setBackground(Color.decode("#171717"));
        chatArea.setForeground(Color.decode("#f5f5f5"));
        JScrollPane chatScrollable = new JScrollPane(chatArea);
        add(chatScrollable, BorderLayout.CENTER);

        jListOfUsers = new JList(new DefaultListModel());
        jListOfUsers.setPreferredSize(new Dimension(120, 1));
        jListOfUsers.setFont(chatFont);
        jListOfUsers.setBackground(Color.decode("#171717"));
        jListOfUsers.setForeground(Color.decode("#f5f5f5"));
        add(jListOfUsers, BorderLayout.EAST);

        msgPanel = new JPanel(new BorderLayout());
        add(msgPanel, BorderLayout.SOUTH);
        JButton sendMsg = new JButton("SEND");
        msgPanel.add(sendMsg, BorderLayout.EAST);
        msgField = new JTextField();
        msgPanel.add(msgField, BorderLayout.CENTER);

        authPanel  = new JPanel(new GridLayout(1,3));
        add(authPanel, BorderLayout.NORTH);
        jtfLogin = new JTextField();
        jpfPass  = new JPasswordField();
        JButton jbAuth = new JButton("AUTH");
        authPanel.add(jtfLogin);
        authPanel.add(jpfPass);
        authPanel.add(jbAuth);

        setAuthorized(false);

        setVisible(true);
    }

I can't understand what is wrong with that. Please, help me.

CodePudding user response:

I've solved this problem by choosing correct version of JDK. It was incorrect in project structure...

  • Related