|
Фокус на поле в окне диалога
#33364326
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
Участник
Откуда: Протвино
Сообщения: 709
|
|
Имеется форма соединения с БД. Можно ли как-то переместить фокус на поле "имя пользователя", а не на кнопку при старте диалога? Так и не смог понять.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173.
package forms;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FocusTraversalPolicy;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Hashtable;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutFocusTraversalPolicy;
import oracle.jbo.JboContext;
import oracle.jbo.client.Configuration;
import oracle.jbo.common.PropertyConstants;
import oracle.jbo.common.PropertyMetadata;
import oracle.jbo.common.ampool.DefaultConnectionStrategy;
import oracle.jbo.common.ampool.EnvInfoProvider;
public class JCLoginDialog
extends JPanel
implements EnvInfoProvider
{
/**Constructor taking a parent Form as parameter
*/
public JCLoginDialog(JFrame parent)
{
super ();
this .parent = parent;
try
{
jbInit();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public Dimension getPreferredSize()
{
return new Dimension( 350 , 110 );
}
/**The default constructor
*/
public JCLoginDialog()
{
this ( null );
}
private BorderLayout outerLayout = new BorderLayout();
private JPanel inputPanel = new JPanel();
private GridBagLayout panelLayout = new GridBagLayout();
private JLabel labelUserName = new JLabel();
private JTextField mUserName = new JTextField();
private JLabel labelPassword = new JLabel();
private JPasswordField mPassword = new JPasswordField();
private JLabel mErrorMessage = new JLabel();
private JFrame parent;
private String[] options =
{ "OK", "Отмена" };
public Dimension getMinimumSize()
{
return getPreferredSize();
}
/**the JbInit method
*/
public void jbInit()
{
setLayout(outerLayout);
inputPanel.setLayout(panelLayout);
inputPanel.add(labelUserName, new GridBagConstraints( 0 , 0 , 1 , 1 , 0 . 0 , 0 . 0 , GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets( 0 , 0 , 0 , 5 ), 1 , 1 ));
inputPanel.add(mUserName, new GridBagConstraints( 1 , 0 , 1 , 1 , 0 . 0 , 0 . 0 , GridBagConstraints.WEST, GridBagConstraints
.NONE, new Insets( 0 , 0 , 0 , 5 ), 165 , 1 ));
labelUserName.setLabelFor(mUserName);
mUserName.setToolTipText("Имя пользователя");
labelUserName.setText("Пользователь :");
inputPanel.add(labelPassword, new GridBagConstraints( 0 , 1 , 1 , 1 , 0 . 0 , 0 . 0 , GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets( 0 , 0 , 0 , 5 ), 1 , 1 ));
inputPanel.add(mPassword, new GridBagConstraints( 1 , 1 , 500 , 1 , 0 . 0 , 0 . 0 , GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets( 0 , 0 , 0 , 5 ), 165 , 1 ));
labelPassword.setLabelFor(mPassword);
mPassword.setToolTipText("Пароль для входа в БД");
labelPassword.setText("Пароль :");
this .add(inputPanel, BorderLayout.CENTER);
this .add(mErrorMessage, BorderLayout.SOUTH);
this .setFocusTraversalPolicy( new LayoutFocusTraversalPolicy());
}
public boolean popupDialog()
{
int result = JOptionPane.showOptionDialog(parent, this , "Вход в систему", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null , options, options[ 0 ]);
switch (result)
{
case 0 :
return true;
default :
return false;
}
}
public void modifyInitialContext(Object initialContext)
{
}
public Object getInfo(String info, Object connEnvironment)
{
RuntimeException exc =
((RuntimeException)((Hashtable)connEnvironment).get(DefaultConnectionStrategy
.LAST_EXCEPTION));
if (exc == null )
{
mErrorMessage.setText("");
}
else
{
mErrorMessage.setText("Неверный пароль/имя пользователя");
}
String username = (String)((Hashtable)connEnvironment).get(Configuration.DB_USERNAME_PROPERTY);
String password = (String)((Hashtable)connEnvironment).get(Configuration.DB_PASSWORD_PROPERTY);
boolean isUsernameEmpty = ((username == null ) || (username.length() <= 0 ));
boolean isPasswordEmpty = ((password == null ) || (password.length() <= 0 ));
if (isUsernameEmpty)
{
username = new String(mUserName.getText()).trim();
isUsernameEmpty = ((username == null ) || (username.length() <= 0 ));
}
if (isPasswordEmpty)
{
password = new String(mPassword.getPassword()).trim();
isPasswordEmpty = ((password == null ) || (password.length() <= 0 ));
}
if (isUsernameEmpty || isPasswordEmpty || exc != null )
{
if (!popupDialog())
{
throw new IllegalArgumentException("Вход прерван");
}
}
((Hashtable)connEnvironment).put(Configuration.DB_USERNAME_PROPERTY, mUserName.getText().trim());
((Hashtable)connEnvironment).put(Configuration.DB_PASSWORD_PROPERTY, new String(mPassword.getPassword()).trim());
return null ;
}
public int getNumOfRetries()
{
return 3 ;
}
}
Nai tiruvantel ar varyuvantel i Valar tieyanna nu vilya
|
|
|