עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

מישהו מכיר component כמו JTextArea שמאפשר טקסט בצבעים? (בJAVA)

Featured Replies

פורסם

כתבתי צ'ט, וכאשר הclient מקבל הודעה פרטית אני רוצה שהכתוב יופיע בצבע שונה מהרגיל.

גיליתי שJTextArea לא טוב לשם כך, כך שעלי לשנות את מה שהיה עד עכשיו ולשים במקום component חדש.

מצאתי ברשת שJTextPane יכול להציג בצבעים אבל השימוש איתו מסורבל מעט כיוון שאין מתודה append שפשוט מקבלת string וצבע.

אמנם מצאתי מתודה מוכנה כזו באתר הבא:

http://www.java2s.com/Code/Java/Swing-JFC/ExtensionofJTextPanethatallowstheusertoeasilyappendcoloredtexttothedocument.htm

אבל זה לא עובד משום מה ולא מוצג כלום בתוך הקומפוננט הזה.

בכל מקרה, אם מישהו יוכל להסביר לי איך להשתמש בJTextPane או אולי מכיר קומפוננט אחרת שטובה למקרה שלי- אודה לו מאוד!

פורסם

גם אני כתבתי מזמן איזה תוכנת צ'אט, הנה הפונקציה שכתבתי בשביל לצבוע את שם המשתמש

TP_output מסוג Jtextpane


private void WriteNickName(String msg,Color color)
{
try {


StyledDocument doc = (StyledDocument)TP_Output.getDocument();
Style style = doc.addStyle("StyleName", null);
Calendar now = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm ");
StyleConstants.setForeground(style,color);
doc.insertString(doc.getLength(),msg+"("+formatter.format(now.getTime())+")"+":\n", style);

} catch (BadLocationException e) {
}

}

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.