Class: javaxjavax::swing::JFrame
- Inherits:
-
Object
- Object
- javaxjavax::swing::JFrame
- Defined in:
- lib/simple_gui_creator/jframe_helper_methods.rb
Overview
helper/english friendlier methods for JFrame
Defined Under Namespace
Classes: CloseListener
Instance Method Summary collapse
- #after_closed(&block) ⇒ Object
- #after_minimized(&block) ⇒ Object
- #after_restored_either_way(&block) ⇒ Object
- #always_on_top=(bool) ⇒ Object
-
#always_on_top_original ⇒ Object
avoid jdk6 always on top bug betterlogic.com/roger/2012/04/jframe-setalwaysontop-doesnt-work-after-using-joptionpane/.
-
#bring_to_front ⇒ Object
kludgey…but said to work for swing frames…
- #close ⇒ Object
- #dispose_on_close ⇒ Object
-
#initialize(*args) ⇒ JFrame
constructor
A new instance of JFrame.
- #maximize ⇒ Object
- #minimize ⇒ Object
- #restore ⇒ Object (also: #unminimize)
- #set_always_on_top(bool) ⇒ Object
- #setAlwaysOnTop(bool) ⇒ Object
Constructor Details
#initialize(*args) ⇒ JFrame
Returns a new instance of JFrame.
36 37 38 39 40 41 42 43 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 36 def initialize *args super(*args) # we do always get here... # because we do this, you should *not* have to call the unsafe: # setDefaultCloseOperation(EXIT_ON_CLOSE) # which basically does a System.exit(0) when the last jframe closes. Yikes jdk, yikes. #addWindowListener(CloseListener.new(self)) dispose_on_close # don't keep running after being closed, and prevent the app from exiting! whoa! end |
Instance Method Details
#after_closed(&block) ⇒ Object
53 54 55 56 57 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 53 def after_closed &block addWindowListener(CloseListener.new(self) { block.call }) end |
#after_minimized(&block) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 59 def after_minimized &block addWindowStateListener {|e| if e.new_state == java::awt::Frame::ICONIFIED block.call else #puts 'non restore' end } end |
#after_restored_either_way(&block) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 69 def after_restored_either_way &block addWindowStateListener {|e| if e.new_state == java::awt::Frame::NORMAL block.call else #puts 'non restore' end } end |
#always_on_top=(bool) ⇒ Object
106 107 108 109 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 106 def always_on_top=bool always_on_top_original false always_on_top_original bool end |
#always_on_top_original ⇒ Object
avoid jdk6 always on top bug betterlogic.com/roger/2012/04/jframe-setalwaysontop-doesnt-work-after-using-joptionpane/
104 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 104 alias always_on_top_original always_on_top= |
#bring_to_front ⇒ Object
kludgey…but said to work for swing frames…
80 81 82 83 84 85 86 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 80 def bring_to_front # kludgey...but said to work for swing frames... java.awt.EventQueue.invokeLater{ unminimize toFront repaint } end |
#close ⇒ Object
45 46 47 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 45 def close dispose # <sigh> end |
#dispose_on_close ⇒ Object
49 50 51 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 49 def dispose_on_close setDefaultCloseOperation JFrame::DISPOSE_ON_CLOSE end |
#maximize ⇒ Object
99 100 101 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 99 def maximize setExtendedState(JFrame::MAXIMIZED_BOTH) end |
#minimize ⇒ Object
88 89 90 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 88 def minimize setState(java.awt.Frame::ICONIFIED) end |
#restore ⇒ Object Also known as: unminimize
92 93 94 95 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 92 def restore setState(java.awt.Frame::NORMAL) # this line is probably enough, but do more just in case... #setVisible(true) end |
#set_always_on_top(bool) ⇒ Object
111 112 113 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 111 def set_always_on_top bool always_on_top=bool end |
#setAlwaysOnTop(bool) ⇒ Object
115 116 117 |
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 115 def setAlwaysOnTop bool always_on_top=bool end |