Class: SensibleSwing::NonBlockingDialog

Inherits:
JDialog
  • Object
show all
Defined in:
lib/swing_helpers.rb

Instance Method Summary collapse

Constructor Details

#initialize(title_and_display_text, close_button_text = 'Close') ⇒ NonBlockingDialog

Returns a new instance of NonBlockingDialog.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/swing_helpers.rb', line 92

def initialize title_and_display_text, close_button_text= 'Close'
  super nil
  lines = title_and_display_text.split("\n")
  set_title lines[0]
  get_content_pane.set_layout nil
  lines.each_with_index{|line, idx|
    jlabel = JLabel.new line
    jlabel.set_bounds(10, 15*idx, 550, 24)
    get_content_pane.add jlabel
  }
  close = JButton.new( close_button_text ).on_clicked {
    self.dispose
  }
  close.set_bounds(125,30+15*lines.length,70,25)
  get_content_pane.add close
  set_size 550, 100+15*lines.length # XXX variable width? or use swing build in better?
  set_visible true
  setDefaultCloseOperation JFrame::DISPOSE_ON_CLOSE
  setLocationRelativeTo nil # center it on the screen
end