Swing application closes right away after launch

195 views Asked by At

I have a simple JRuby Swing application, wich compiled and packed to jar using Warbler. After executing jar file, Swing frame appears and closes right away.

include Java

import java.awt.Font
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.JLabel

class Main
def initialize
@logInWin = JFrame.new
    basic = JPanel.new

    font = Font.new "Verdana", Font::PLAIN, 16

    loginL = JLabel.new "Login"
    loginL.setFont font

    basic.add loginL
    @logInWin.add basic
    @logInWin.pack

    @logInWin.setDefaultCloseOperation JFrame::EXIT_ON_CLOSE
    @logInWin.setSize 350, 350
    @logInWin.setLocationRelativeTo nil
    @logInWin.setTitle "Log In"
    @logInWin.setVisible true
end
end

Main.new

How do I avoid this behaviour?

Environment:

OS: Win 8

Java(TM) SE Runtime Environment (build 1.8.0_11-b12)

Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

jruby 9.0.0.0.rc1 (2.2.2) 2015-06-10 a0bf3b3 Java HotSpot(TM) 64-Bit Server VM 25.11-b03 on 1.8.0_11-b12 +jit [Windows 8-amd64]

Warbler version 1.4.8

1

There are 1 answers

0
diesel On BEST ANSWER

This question already exists: JRuby script with Rubeus and Swing exiting once packaged into jar using warble

Add at the bottom of the main script:

event_thread = nil
SwingUtilities.invokeAndWait { event_thread = java.lang.Thread.currentThread }
event_thread.join