JTextField: getHorizontalVisibility() : JTextField « javax.swing « Java by API






JTextField: getHorizontalVisibility()

 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoundedRangeModel;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JTextField;

public class MainClass {
  public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Text Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    
    final TextSlider ts = new TextSlider();
    ts.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("Text: " + ts.getText());
      }
    });
    
    
    frame.add(ts, BorderLayout.NORTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
  }

}

class TextSlider extends JPanel {
  private JTextField textField;

  private JScrollBar scrollBar;

  public TextSlider() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    textField = new JTextField();
    scrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
    BoundedRangeModel brm = textField.getHorizontalVisibility();
    scrollBar.setModel(brm);
    add(textField);
    add(scrollBar);
  }

  public JTextField getTextField() {
    return textField;
  }

  public String getText() {
    return textField.getText();
  }

  public void addActionListener(ActionListener l) {
    textField.addActionListener(l);
  }

  public void removeActionListener(ActionListener l) {
    textField.removeActionListener(l);
  }

  public JScrollBar getScrollBar() {
    return scrollBar;
  }
}


           
         
  








Related examples in the same category

1.JTextField.LEFT
2.JTextField.LEADING
3.JTextField.TRAILING
4.new JTextField(String text)
5.new JTextField(String text, int columns)
6.JTextField: addActionListener(ActionListener s)
7.JTextField: addFocusListener(FocusListener l)
8.JTextField: addKeyListener(KeyListener l)
9.JTextField: copy()
10.JTextField: cut()
11.JTextField: getActions()
12.JTextField: getCaretPosition()
13.JTextField: getDocument()
14.JTextField: getHorizontalVisibility() (2)
15.JTextField: getInputMap()
16.JTextField: getKeymap()
17.JTextField: getScrollOffset()
18.JTextField: paste()
19.JTextField: registerKeyboardAction(ActionListener anAction,String aCommand,KeyStroke aKeyStroke,int aCondition)
20.JTextField: requestFocus()
21.JTextField: modelToView(int pos)
22.JTextField: read(Reader in, Object desc)
23.JTextField: setDocument(Document doc)
24.JTextField: setFocusAccelerator(char aKey)
25.JTextField: setHorizontalAlignment(int alignment)
26.JTextField: setInputVerifier(InputVerifier input)
27.JTextField: setPreferredSize(Dimension preferredSize)
28.JTextField: setNavigationFilter(NavigationFilter filter)
29.JTextField: setTransferHandler(TransferHandler newHandler)
30.JTextField: write(Writer out)