0

I'm using java.awt.TextField and what really annoys me is the vertical scrollbar on the right. I wondered if I can disable it? I found the constant "SCROLLBARS_NONE", so I guess it should be possible.

muffin
  • 1,456
  • 4
  • 21
  • 44
  • Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson May 08 '13 at 13:09
  • Yeah, I know that awt isn't the very best, but sometimes I need it rather than a swing component. The swing buttons for example are very ugly compared to the awt buttons – muffin May 08 '13 at 13:27
  • 2
    @muffin Swing has customizable look and feels, if you want it to look like the system skin (as AWT is) then see here: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html#programmatic Essentially, the code you want is `UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());` (with appropriate exceptions caught.) – Michael Berry May 08 '13 at 15:04
  • 1
    @berry120 Wow, I didn't know that this is possible! Thank you very much! – muffin May 10 '13 at 06:52
  • @muffin No problem. Also worth mentioning that if you do require heavyweight components to be used (which is what AWT does) then your best bet is to use SWT - it's a much more modern, still updated library with many more components than AWT. In truth, aside from the supporting of legacy apps there's really not that much reason to use AWT at all these days. – Michael Berry May 10 '13 at 09:10

2 Answers2

1

Use the following constructor for TextArea:

public TextArea(String text,
    int rows,
    int columns,
    int scrollbars)

This way you can use the SCROLLBARS_NONE constant in last value in the constructor.

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
0

Horizontal or Vertical ScrollBar can be removed by the following code while creating TextArea.

TextArea textArea = new TextArea("text", 3 , 100 , TextArea.SCROLLBARS_VERTICAL_ONLY);

Here specify if you want to display only horizontal or vertical scrollbar.This code hides horizontal scrollbar

JavaDragon
  • 431
  • 1
  • 6
  • 17