tag:blogger.com,1999:blog-12823779351597887992008-03-15T17:54:56.482ZSWING WORKERChristoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-1282377935159788799.post-36142523063954999052008-03-15T17:35:00.005Z2008-03-15T17:51:56.758ZThe wizard components JWizardPanel, JWizardDialog<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_L4tSSx7sAl4/R9wJ0qQfB-I/AAAAAAAAAIY/WY9VWXaQ3HM/s1600-h/wizaedview.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp3.blogger.com/_L4tSSx7sAl4/R9wJ0qQfB-I/AAAAAAAAAIY/WY9VWXaQ3HM/s400/wizaedview.png" alt="" id="BLOGGER_PHOTO_ID_5178024471870506978" border="0" /></a>JWizardPanel and JWizardDialog provide a panel and dialog that accomodates a sequence of pages. Three buttons, previous, next and finish are available but one can also add others as required. The wizard navigates through a number of pages represented by a <span style="font-family: courier new;">WizardPage </span>interface. Notifications for wizard events are obtained by adding a <span style="font-family: courier new;">ChangeListener</span>.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_L4tSSx7sAl4/R9wJ9aQfB_I/AAAAAAAAAIg/6rfl6bWeV0U/s1600-h/wizardviewnb.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_L4tSSx7sAl4/R9wJ9aQfB_I/AAAAAAAAAIg/6rfl6bWeV0U/s400/wizardviewnb.png" alt="" id="BLOGGER_PHOTO_ID_5178024622194362354" border="0" /></a><span style="font-family:courier new;">JWizardPanel </span>and <span style="font-family:courier new;">JWizardDialog </span>are JavaBean components so you can add them to the <a href="http://www.netbeans.org/">NetBeans</a> Swing components pallette and use them through the GUI builder. Get the <span style="font-family:courier new;">WizardView</span> NetBeans project including the source files, compiled jar and API javadocs from <a href="http://www.connectina.com/swingworker/WizardView.zip">here</a>.Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comtag:blogger.com,1999:blog-1282377935159788799.post-7846926083519105762008-02-17T09:31:00.004Z2008-02-17T09:50:41.021ZThe titled separator component JTitleSeparator<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_L4tSSx7sAl4/R7f_TnAG_7I/AAAAAAAAAHw/nq7QKzTdOCM/s1600-h/titleseparator.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp1.blogger.com/_L4tSSx7sAl4/R7f_TnAG_7I/AAAAAAAAAHw/nq7QKzTdOCM/s400/titleseparator.png" alt="" id="BLOGGER_PHOTO_ID_5167879809782972338" border="0" /></a>JTitleSeparator is a horizontal line separator with a title. The title can be aligned left, right or center (using <span style="font-family:courier new;">SwingConstants LEFT</span>, <span style="font-family:courier new;">RIGHT</span>, or <span style="font-family:courier new;">CENTER</span>). Use the <span style="font-family:courier new;">setImageAlignment </span>method to place an image on the left or right side of the text. A title or image can be specified through one of the constructors or using the <span style="font-family:courier new;">setTitle </span>and <span style="font-family:courier new;">setImage </span>methods.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_L4tSSx7sAl4/R7f_aXAG_8I/AAAAAAAAAH4/eoEswxkTt00/s1600-h/titleseparatornb.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp0.blogger.com/_L4tSSx7sAl4/R7f_aXAG_8I/AAAAAAAAAH4/eoEswxkTt00/s400/titleseparatornb.png" alt="" id="BLOGGER_PHOTO_ID_5167879925747089346" border="0" /></a><span style="font-family:courier new;">JTitleSeparator </span>is a JavaBean component so you can add it to the <a href="http://www.netbeans.org/">NetBeans</a> Swing components pallette and use it through the GUI builder. Get the <span style="font-family:courier new;">JTitleSeparator</span> NetBeans project including the source files, compiled jar and API javadocs from <a href="http://www.connectina.com/swingworker/TitleSeparator.zip">here</a>.Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comtag:blogger.com,1999:blog-1282377935159788799.post-74269681843506094362008-02-08T18:41:00.000Z2008-02-08T19:24:37.219ZThe popup button component JPopupButton<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_L4tSSx7sAl4/R6ypy3Xx3lI/AAAAAAAAAHQ/mUvcocnJkS4/s1600-h/popupbutton.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_L4tSSx7sAl4/R6ypy3Xx3lI/AAAAAAAAAHQ/mUvcocnJkS4/s400/popupbutton.png" alt="" id="BLOGGER_PHOTO_ID_5164689564009356882" border="0" /></a>JPopupButton is a button that gives access to a popup menu. The button has a small arrow indicator on the bottom right. Use the <span style="font-family: courier new;">addMenuItem </span>or <span style="font-family: courier new;">addComponent </span>methods in order to add options to the popup menu.<br /><span style="font-family: courier new;"></span><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_L4tSSx7sAl4/R6yp-HXx3mI/AAAAAAAAAHY/0FhVd3tLLG0/s1600-h/popupbuttonnb.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp3.blogger.com/_L4tSSx7sAl4/R6yp-HXx3mI/AAAAAAAAAHY/0FhVd3tLLG0/s400/popupbuttonnb.png" alt="" id="BLOGGER_PHOTO_ID_5164689757282885218" border="0" /></a><span style="font-family: courier new;">JPopupButton </span>is a JavaBean component so you can add it to the <a href="http://www.netbeans.org/">NetBeans</a> Swing components pallette and use it through the GUI builder. Get the <span style="font-family: courier new;">JPopupButton</span> NetBeans project including the source files, compiled jar and API javadocs from <a href="http://www.connectina.com/swingworker/PopupButton.zip">here</a>.Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comtag:blogger.com,1999:blog-1282377935159788799.post-36858575605707357632008-01-25T22:37:00.000Z2008-01-25T22:51:22.669ZThe month selection component JMonthBox<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_L4tSSx7sAl4/R5pk5XXx3jI/AAAAAAAAAGU/Rn-W70BGp_Q/s1600-h/monthbox.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_L4tSSx7sAl4/R5pk5XXx3jI/AAAAAAAAAGU/Rn-W70BGp_Q/s400/monthbox.png" alt="" id="BLOGGER_PHOTO_ID_5159547259795398194" border="0" /></a><span style="font-family:courier new;">JMonthBox</span> is a month selection component combining a combo box and a rolling spinner. One can obtain the currently selected month through the <span style="font-family:courier new;">getSelectedMonth </span>or <span style="font-family:courier new;">getSelectedMonthNumber </span>methods. Alternatively, use the <span style="font-family:courier new;">addMonthChangeListener </span>to get notifications of selection changes. The month names can be either those associated with the current locale or custom names.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_L4tSSx7sAl4/R5plA3Xx3kI/AAAAAAAAAGc/gTJeaqOoM4Q/s1600-h/monthboxnb.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp0.blogger.com/_L4tSSx7sAl4/R5plA3Xx3kI/AAAAAAAAAGc/gTJeaqOoM4Q/s400/monthboxnb.png" alt="" id="BLOGGER_PHOTO_ID_5159547388644417090" border="0" /></a><br /><span style="font-family:courier new;">JMonthBox</span> is a JavaBean component so you can add it to the <a href="http://www.netbeans.org/">NetBeans</a> Swing components pallette and use it through the GUI builder. Get the <span style="font-family:courier new;">JMonthBox</span> NetBeans project including the source files, compiled jar and API javadocs from <a href="http://www.connectina.com/swingworker/MonthBox.zip">here</a>.Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comtag:blogger.com,1999:blog-1282377935159788799.post-30055349048717441772008-01-13T10:17:00.000Z2008-01-13T22:05:57.858ZThe link label component JLinkLabel<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_L4tSSx7sAl4/R4qLOqSJp1I/AAAAAAAAAGI/BiW85QcPg68/s1600-h/linklabel.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp3.blogger.com/_L4tSSx7sAl4/R4qLOqSJp1I/AAAAAAAAAGI/BiW85QcPg68/s400/linklabel.png" alt="" id="BLOGGER_PHOTO_ID_5155085807463802706" border="0" /></a><span style="font-family:courier new;">JLinkLabel </span>is a web link-like Swing label component. It allows customization of the link color, the hover color when the cursor is over the link and the press color when the link is pressed. A hand cursor appears when the cursor moves over the link to indicate that it can be pressed.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_L4tSSx7sAl4/R4noJ6SJp0I/AAAAAAAAAFo/8oTWnzaytKQ/s1600-h/linklabelnb.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp3.blogger.com/_L4tSSx7sAl4/R4noJ6SJp0I/AAAAAAAAAFo/8oTWnzaytKQ/s400/linklabelnb.png" alt="" id="BLOGGER_PHOTO_ID_5154906505464096578" border="0" /></a><br /><span style="font-family:courier new;">JLinkLabel </span>is a JavaBean component so you can add it to the <a href="http://www.netbeans.org/">NetBeans</a> Swing components pallette and use it through the GUI builder. Get the <span style="font-family:courier new;">JLinkLabel </span>NetBeans project including the source files, compiled jar and API javadocs from <a href="http://www.connectina.com/swingworker/LinkLabel.zip">here</a>.Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comtag:blogger.com,1999:blog-1282377935159788799.post-65150523803981499082008-01-03T17:22:00.000Z2008-01-03T18:07:37.426ZThe program status bar component JStatusPanel<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_L4tSSx7sAl4/R30ctaSJpxI/AAAAAAAAAEg/T_cKsC-H_zU/s1600-h/statuspanel.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp1.blogger.com/_L4tSSx7sAl4/R30ctaSJpxI/AAAAAAAAAEg/T_cKsC-H_zU/s400/statuspanel.png" alt="" id="BLOGGER_PHOTO_ID_5151305115256858386" border="0" /></a><span style="font-family:courier new;">JStatusPanel </span>is a Swing status bar component that consists of a message label, status label and a status indicator. Additional Swing components can be added or removed as required. The text of the message and status labels can optionally appear for a few seconds and then disappear.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_L4tSSx7sAl4/R30c-qSJpyI/AAAAAAAAAEo/G_PvoMPXeTk/s1600-h/statuspanelnb.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_L4tSSx7sAl4/R30c-qSJpyI/AAAAAAAAAEo/G_PvoMPXeTk/s400/statuspanelnb.png" alt="" id="BLOGGER_PHOTO_ID_5151305411609601826" border="0" /></a><br /><span style="font-family:courier new;">JStatusPanel </span>is a JavaBean component so you can add it to the <a href="http://www.netbeans.org/">NetBeans</a> Swing components pallette and use it through the GUI builder. Get the <span style="font-family:courier new;">JStatusPanel </span>NetBeans project including the source files, compiled jar and API javadocs from <a href="http://www.connectina.com/swingworker/StatusPanel.zip">here</a>.Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comtag:blogger.com,1999:blog-1282377935159788799.post-11145143154417817862008-01-01T23:13:00.000Z2008-01-01T23:56:24.262ZProgrammatically compile and execute java code with RunnerPad<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_L4tSSx7sAl4/R3rRXqSJpvI/AAAAAAAAAEQ/q-xfFDi-kaY/s1600-h/runner.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp3.blogger.com/_L4tSSx7sAl4/R3rRXqSJpvI/AAAAAAAAAEQ/q-xfFDi-kaY/s400/runner.png" alt="" id="BLOGGER_PHOTO_ID_5150659328269199090" border="0" /></a><br />One of my favorite articles from <a href="http://www.javaworld.com/">JavaWorld</a> was called <a href="http://www.javaworld.com/javatips/jw-javatip131.html">"Make a statement with javac!"</a> and described code that programmatically compiled and executed Java statements. Since 2002 when this article was written the relevant APIs have changed. Java SE 6 supports this functionality through the <span style="font-family:courier new;">JavaCompiler </span>and <span style="font-family:courier new;">ToolProvider </span>classes of the <span style="font-family:courier new;">javax.tools</span> package. With these in mind I created RunnerPad, a Swing program that allows users to quickly write, compile and run Java statements. RunnerPad can be downloaded as a <a href="http://www.netbeans.org/">NetBeans</a> project from <a href="http://www.connectina.com/swingworker/Runner.zip">here</a>.Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comtag:blogger.com,1999:blog-1282377935159788799.post-91868291018884143902007-12-28T09:24:00.000Z2007-12-28T10:08:52.289ZLine number in a JTextArea<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_L4tSSx7sAl4/R3TGWqSJptI/AAAAAAAAAD8/jj_e_NtgsJk/s1600-h/linenumber.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp1.blogger.com/_L4tSSx7sAl4/R3TGWqSJptI/AAAAAAAAAD8/jj_e_NtgsJk/s320/linenumber.png" alt="" id="BLOGGER_PHOTO_ID_5148958366601160402" border="0" /></a><br />The code below looks for the caret position in a <span style="font-family:courier new;">JTextArea </span>and returns the current line number.<br /><pre><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b>public </b></span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b>int </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >getCurrentLineNumber</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >() {</span><span style="font-size:100%;"><br /></span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b> int </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >line;</span><span style="font-size:100%;"><br /></span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b> int </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >caretPosition = editorTextArea.getCaretPosition</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >()</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >;</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" > Element root =<br /> editorTextArea.getDocument</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >()</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >.getDefaultRootElement</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >()</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >;</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" > line = root.getElementIndex</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >(</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >caretPosition</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >) </span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >+ </span><span style="color: rgb(153, 0, 0);font-family:courier new;font-size:100%;" >1</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >;</span><span style="font-size:100%;"><br /></span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b> return </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >line;</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >}</span><span style="font-size:85%;"><br /></span><br /></pre>The method can be used by a <span style="font-family:courier new;">CaretListener</span> implementation so that every time we move the caret inside the JTextArea we get an update on the current line number.Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comtag:blogger.com,1999:blog-1282377935159788799.post-89007199375026382622007-12-27T16:04:00.000Z2007-12-27T21:38:46.316ZRedirect System.out / System.err to a JTextArea<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_L4tSSx7sAl4/R3PVuKSJprI/AAAAAAAAADg/J2_gV4LHWG8/s1600-h/redirectout.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_L4tSSx7sAl4/R3PVuKSJprI/AAAAAAAAADg/J2_gV4LHWG8/s320/redirectout.png" alt="" id="BLOGGER_PHOTO_ID_5148693788025792178" border="0" /></a>The following code redirects text from <span style="font-family:courier new;">System.out</span> and <span style="font-family:courier new;">System.err</span> to a <span style="font-family:courier new;">JTextArea.</span><br /><br /><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >PrintStream out = </span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:85%;" ><b>new </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >PrintStream</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:85%;" ><b>new </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >TextAreaOutputStream</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >())</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >;</span><span style=";font-family:courier new;font-size:85%;" ><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >System.setOut</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >out</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >)</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >;</span><span style=";font-family:courier new;font-size:85%;" ><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >System.setErr</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >out</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >)</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >;</span><br /><br /><span style="font-family:courier new;">TextAreaOutputStream </span>overrides the abstract OutputStream class to append characters to a <span style="font-family:courier new;">JTextArea</span> named <span style="font-family:courier new;">outputTextArea</span>.<br /><pre><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b><br /><span style="font-size:100%;">public class </span></b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >TextAreaOutputStream </span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b>extends </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >OutputStream </span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >{</span><span style=";font-family:courier new;font-size:100%;" ><br /></span><span style=";font-family:courier new;font-size:100%;" ><br /></span><span style="font-size:100%;"> </span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b>public </b></span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b>void </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >write</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >(</span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b>int </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >b</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >) </span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b>throws </b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >IOException </span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >{</span><span style=";font-family:courier new;font-size:100%;" ><br /></span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" > outputTextArea.append</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >(</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >String.valueOf</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >((</span><span style="color: rgb(127, 0, 85);font-family:courier new;font-size:100%;" ><b>char</b></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >) </span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >b</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >))</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >;</span><span style=";font-family:courier new;font-size:100%;" ><br /></span><span style="color: rgb(255, 255, 255);font-family:courier new;font-size:100%;" > </span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" > }</span><span style="color: rgb(255, 255, 255);font-family:courier new;font-size:100%;" > </span><span style=";font-family:courier new;font-size:100%;" ><br /></span></pre><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:100%;" >}</span>Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.comtag:blogger.com,1999:blog-1282377935159788799.post-33554942314783008132007-12-26T14:44:00.001Z2007-12-27T21:35:17.784Zi18n for standard Swing dialogs<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_L4tSSx7sAl4/R3KfyaSJpoI/AAAAAAAAADI/XU79-2ViNEs/s1600-h/bgchooser.png"><img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;" src="http://bp2.blogger.com/_L4tSSx7sAl4/R3KfyaSJpoI/AAAAAAAAADI/XU79-2ViNEs/s200/bgchooser.png" alt="" id="BLOGGER_PHOTO_ID_5148353012435625602" border="0" /></a><br />Swing dialog components like <span style="font-family:courier new;">JOptionPane</span> and <span style="font-family:courier new;">JFileChooser </span>are provided with i18n support for a number of languages. Still, there are times when the language we require is not supported or we want to have complete control on the displayed text. The following example code shows how we can override the default text using the <span style="font-family:courier new;">UIManager </span>and a <span style="font-family:courier new;">ResourceBundle</span>.<br /><br /><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >UIManager.put</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"OptionPane.yesButtonText"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >, bundle.getString</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"common.yes"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >))</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >;</span><span style="font-size:85%;"><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >UIManager.put</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"OptionPane.cancelButtonText"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >, bundle.getString</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"common.cancel"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >))</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >;</span><span style="font-size:85%;"><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >UIManager.put</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"OptionPane.noButtonText"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >, bundle.getString</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"common.no"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >))</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >;</span><span style="font-size:85%;"><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >UIManager.put</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"OptionPane.okButtonText"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >, bundle.getString</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"common.ok"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >))</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >;</span><span style="font-size:85%;"><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >UIManager.put</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"FileChooser.saveButtonText"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >, bundle.getString</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"common.save"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >))</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >;</span><span style="font-size:85%;"><br /></span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >UIManager.put</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"FileChooser.cancelButtonText"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >, bundle.getString</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >(</span><span style="color: rgb(42, 0, 255);font-family:courier new;font-size:85%;" >"common.cancel"</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >))</span><span style="color: rgb(0, 0, 0);font-family:courier new;font-size:85%;" >;</span><span style="font-size:85%;"><br /></span><br />The strings that can be customized for a <span style="font-family:courier new;">JOptionPane</span> and a <span style="font-family:courier new;">JFileChooser </span>are:<br /><br /><span style=";font-family:courier;font-size:85%;" ><span style="font-family:courier new;">OptionPane.yesButtonText</span> <span style="font-family:courier new;"><br />OptionPane.noButtonText</span><br /><span style="font-family:courier new;"></span><span style="font-family:courier new;">OptionPane.cancelButtonText</span><br /><span style="font-family:courier new;">OptionPane.okButtonText</span><br /><br /><span style="font-family:courier new;">FileChooser.newFolderErrorText</span> <span style="font-family:courier new;"><br />FileChooser.newFolderErrorSeparator</span> <span style="font-family:courier new;"><br />FileChooser.fileDescriptionText</span> <span style="font-family:courier new;"><br />FileChooser.directoryDescriptionText</span> <span style="font-family:courier new;"><br />FileChooser.saveButtonText</span> <span style="font-family:courier new;"><br />FileChooser.openButtonText</span> <span style="font-family:courier new;"><br />FileChooser.saveDialogTitleText<br /></span><span style="font-family:courier new;">FileChooser.openDialogTitleText<br /></span><span style="font-family:courier new;">FileChooser.cancelButtonText</span> <span style="font-family:courier new;"><br />FileChooser.updateButtonText</span> <span style="font-family:courier new;"><br />FileChooser.helpButtonText</span> <span style="font-family:courier new;"><br />FileChooser.directoryOpenButtonText</span> <span style="font-family:courier new;"><br />FileChooser.saveButtonToolTipText</span> <span style="font-family:courier new;"><br />FileChooser.openButtonToolTipText</span><br /><span style="font-family:courier new;">FileChooser.cancelButtonToolTipText</span> <span style="font-family:courier new;"><br />FileChooser.updateButtonToolTipText</span> <span style="font-family:courier new;"><br />FileChooser.helpButtonToolTipText</span> <span style="font-family:courier new;"><br />FileChooser.directoryOpenButtonToolTipText</span><br /><br /></span>Christoshttp://www.blogger.com/profile/11903246349533401198noreply@blogger.com