java Texteditor . nur teilstring kursiv . aber wie?

  • Themenstarter Themenstarter greece28
  • Beginndatum Beginndatum
Status
Nicht offen für weitere Antworten.
G

greece28

Gast
Hi,

ich möchte, dass mein markierter Text kursiv / bold wird... momentan bekomme ich nur alles oder nix 😉 hin...
probiere schon seit einer Weile herum... hat da jemand eine Idee??

Danke ... so sieht's momentan aus.

Code:
protected void formatFett() {
		Font f = textAreaText.getFont();
		int stil = f.getStyle();

		if (buttonFett.isSelected()) {
			stil |= Font.BOLD;
		} else {
			stil ^= Font.BOLD;
		}

		textAreaText.setFont(f.deriveFont(stil));
	}

	protected void formatKursiv() {
		Font f = textAreaText.getFont();
		int stil = f.getStyle();

		if (buttonKursiv.isSelected()) {
			stil |= Font.ITALIC;
		} else {
			stil ^= Font.ITALIC;
		}

		textAreaText.setFont(f.deriveFont(stil));
	}
 
dachte vielleicht selectedText() auf dem Teilstring und dann krieg ich aber nicht mehr die Kurve zum Font....
 
ich könnte natürlich eine neue Textarea machen ... mit Inhalt des Teilstrings... hehe ... aber das ist glaub ich nicht gerade supi implementiert...
 
schnipp
Code:
private Hashtable<Object, Action> actionHash;

private void initActionTable() {
		actionHash = new Hashtable<Object, Action>();
		StyledEditorKit editorKit = (StyledEditorKit) textPane.getEditorKit();
		Action[] actions = editorKit.getActions();
		for (int i = 0; i < actions.length; i++) {
			Action action = actions[i];
			actionHash.put(action.getValue(Action.NAME), action);
		}
	}

buttonFett.addActionListener((Action) actionHash.get("font-bold"));
schnapp

funkt 8)
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben