The list of methods to do JTextField are organized into topic(s).
boolean
addHighlight(JTextField label, MouseEvent mouseEvent1, MouseEvent mouseEvent2) Highlight the given label from the first mouse event to the second Returns true if the highlight was successful, false otherwise.
FontMetrics fm = label.getFontMetrics(label.getFont());
int firstXpos = mouseEvent1.getX();
int lastXpos = mouseEvent2.getX();
int firstOffset = getCharOffset(fm, label.getText(), firstXpos);
int lastOffset = getCharOffset(fm, label.getText(), lastXpos);
if (lastOffset != firstOffset) {
if (firstOffset > lastOffset) {
int tmp = firstOffset;
...
void
addPlaceHolder(final JTextField field, final String placeHolderText) add Place Holder
field.addFocusListener(new FocusListener() {
private Color fontColor = field.getForeground();
public void focusGained(FocusEvent arg0) {
if (field.getText().equals(placeHolderText)) {
field.setText("");
field.setForeground(fontColor);
public void focusLost(FocusEvent arg0) {
if (field.getText().trim().equals("")) {
fontColor = field.getForeground();
field.setForeground(Color.GRAY);
field.setText(placeHolderText);
});
if (field.getText().trim().equals("")) {
field.setText(placeHolderText);
field.setForeground(Color.GRAY);
void
addStyle(JTextField textField, String labelName) add Style
textField.setHorizontalAlignment(SwingConstants.RIGHT);
Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
TitledBorder titled = BorderFactory.createTitledBorder(line, labelName);
titled.setTitleFont(new Font("Verdana", 0, 13));
titled.setTitleColor(new Color(213, 225, 185));
Border empty = new EmptyBorder(5, 8, 5, 8);
CompoundBorder border = new CompoundBorder(titled, empty);
textField.setBorder(border);
...
void
adjustTextToRight(JTextField textField) Metodo que quita los espacios que estan solo al final del texto en el jTextField entregado
String text = textField.getText();
String newText = "";
boolean segmentWithoutLetters = false;
for (int i = 0; i < text.length(); i++) {
if (text.substring(i, text.length()).trim().isEmpty())
segmentWithoutLetters = !segmentWithoutLetters;
if (!segmentWithoutLetters)
newText += text.charAt(i);
...
void
applyDefaultProperties(final JTextField comp) Sets default background and foreground color as well as a default font for the specified component.
if (comp == null) {
return;
applyProperties(comp, "TextField.background",
"TextField.foreground",
"TextField.font");
void
badField(JTextField field) Beeps to report the error, moves focus to specified field and selects all its content.
field.getToolkit().beep();
field.selectAll();
field.requestFocus();