A-SM
A-SM

Reputation: 884

JTextArea indentation

I'm having a problem with JTextArea (not a problem though). I want to create my own college program, one of the function is to write down and save a list of homework each day. It's text area having the main function here, which is to type everything my lecturer said. But text area will act like Windows original notepad, which is not keeping the indentation. So my questions are:

  1. How do I have a function where I press the SHIFT+TAB key it will decrease indentation by one.

  2. If number 1 is possible, then how do my program have behaviour when I press ENTER key, it will have a new line with previous indentation? Just like NetBeans and other IDE.

Edited: I'm a beginner in Java, in truth, I'm making this program while studying Java in my college.

Upvotes: 0

Views: 736

Answers (2)

Duncan Jones
Duncan Jones

Reputation: 69339

How do I have a function where I press the SHIFT+TAB key it will decrease indentation by one.

You need to use key bindings to listen for the user typing Shift+Tab.

If number 1 is possible, then how do my program have behavior when I press ENTER key, it will have a new line with previous indentation? Just like NetBeans and other IDE.

Use a similar piece of logic to capture the Enter key presses. Then, check the previous line in the editor and count the number of tab characters preceding the text. Output a similar number at the start of the new line.

Upvotes: 1

Ashok_udhay
Ashok_udhay

Reputation: 1

you could use Javascript/jquery for indenting by inserting empty space of specific line. while pressing your hot key combination call function to insert five spaces on your cursor.

Upvotes: 0

Related Questions