java - use multi languages in swing application -


we can use several font styles in swing application , can assign different font style different swing text fields. there way configure 1 jtextfield in java swing application support multi languages. example input address.

12b "street name in other language"

jtextfield field = new jtextfield("example",30); font font = new font("courier", font.bold,12); field.setfont(font); 

how can achieve this? there font support dual font style (english + french).

update after first answer

also need send typed text database , retrieve same format. think not possible switch between font dynamically.

update 2

if consider microsoft word can use multiple fonts in single page. there should algorithm save typed letters respective font. how can make kind of behavior in swing without making 2 text fields different language inputs.

enter image description here

you can mix fonts using html tags if change component jtextpane. code below create field containing text "hello world" font times new roman "hello" , courier "world!":

jtextpane field = new jtextpane(); field.setcontenttype("text/html"); field.settext("<html><font face=\"times new roman\">hello</font> <font face=\"courier\">world!</font></html>"); 

here runnable example:

public static void main(string[] args) throws interruptedexception {     multifontfield text = new multifontfield();     jframe frame = new jframe();      text.appendtext("hello ", "times new roman").appendtext("world!", "courier").finalisetext();      frame.add(text);     frame.setsize(200, 50);          frame.setvisible(true); } 

here multifontfield class:

public class multifontfield extends jtextpane {      private stringbuilder content;      public multifontfield() {         super();         this.content = new stringbuilder("<html>");         this.setcontenttype("text/html");     }      public multifontfield appendtext(string text, string font) {         content.append("<font face=\"").append(font).append("\">").append(text).append("</font>");         return this;     }      public void finalisetext() {         this.settext(content.append("</html>").tostring());     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -