rubyfxruby

FXMessageBox in Ruby


I'm working with FXRuby, and I'm trying to figure out how to have an error dialog box, similar to

JOptionPane.showMessageDialog(null, "Error", "Error!", JOptionPane.ERROR_MESSAGE); 

in Java. The closest equivalent I have found is FXMessageBox.error, however usage of this method is seemingly impossible. The documentation specifies the follow parameters in order, FXMessageBox.error(owner, opts, caption, message). I have tried this so far

app = FXApp.new

FXMessageBox.error(app, nil, 'Error', 'Error!')

However, it gives me the error

Wrong arguments for overloaded method 'FXMessageBox.error'.

When I try to do

FXMessageBox.error(app, FXMessageBox::MBOX_OK, 'Error', 'Error!')

I get

FXMessageBox::create: trying to create window before creating parent window.

How do I create the requested Error box?


Solution

  • MBOX_OK is required, as you said. If you create the application before you run it, you should see the error dialog. Here is a working example:

    require 'fox16'
    include Fox
    
    app = FXApp.new
    app.create
    FXMessageBox.error(app, MBOX_OK, 'Error', 'Error!')
    app.run