Class: javaxjavax::swing::JFrame

Inherits:
Object
  • Object
show all
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

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_originalObject



104
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 104

alias always_on_top_original always_on_top=

#bring_to_frontObject

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

#closeObject



45
46
47
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 45

def close
  dispose # <sigh>
end

#dispose_on_closeObject



49
50
51
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 49

def dispose_on_close
  setDefaultCloseOperation JFrame::DISPOSE_ON_CLOSE
end

#maximizeObject



99
100
101
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 99

def maximize
  setExtendedState(JFrame::MAXIMIZED_BOTH)
end

#minimizeObject



88
89
90
# File 'lib/simple_gui_creator/jframe_helper_methods.rb', line 88

def minimize
  setState(java.awt.Frame::ICONIFIED)
end

#restoreObject 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