{"id":1857,"date":"2014-06-10T09:58:00","date_gmt":"2014-06-10T14:58:00","guid":{"rendered":"http:\/\/linuxitos.com\/main\/crear-ventanas-jdialoge-tipo-modal\/"},"modified":"2014-06-10T09:58:00","modified_gmt":"2014-06-10T14:58:00","slug":"crear-ventanas-jdialoge-tipo-modal","status":"publish","type":"post","link":"https:\/\/linuxitos.com\/main\/crear-ventanas-jdialoge-tipo-modal\/","title":{"rendered":"Crear ventanas jdialoge tipo modal"},"content":{"rendered":"<div style=\"text-align: justify;\">En uno de mis proyectos de IHC necesitaba crear un mensaje de di\u00e1logo personalizado. Dicho mensaje deb\u00eda ser enviado a pantalla y desactivar la opci\u00f3n de que el usuario pudiera dar clic o hacer cambios a la ventana desde la que se invocaba dicho mensaje de dialogo. Una opci\u00f3n era utilizar joptionpane, pero no pod\u00eda personalizarlo completamente como yo deseaba, de tal manera que la soluci\u00f3n fue usar jframe de tipo dialoge.<\/div>\n<div style=\"text-align: justify;\">La soluci\u00f3n es la siguiente: El editor usado es netbeans 8.0, no es necesario copiar y pegar todo el c\u00f3digo, creen una jframe un nuevo proyecto en netbeans, sin agregarle ninguna clase, es decir, completamente vac\u00edo. despu\u00e9s creen un nuevo paquete y agreguen un jframe de nomvre ventanaPrincipal, despu\u00e9s un jframeDialoge de nombre ventana2. Una vez realizado esto, modifiquen el c\u00f3digo generado autom\u00e1ticamente por netbeans &nbsp;de tal modo que quede como el siguiente c\u00f3digo. <span style=\"color: red;\">Las l\u00edneas de c\u00f3digo en rojo son las opciones que tienen que modificar.<\/span><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">\/*c\u00f3digo para el jframe ventanaPrincipal*\/<\/div>\n<div style=\"text-align: justify;\">package ventana;<\/div>\n<div style=\"text-align: justify;\">public class ventanaPrincipal extends javax.swing.JFrame {<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; public ventanaPrincipal() {<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; initComponents();<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; setLocationRelativeTo(null); \/*para centrar la ventana principal al iniciar la aplicaci\u00f3n*\/<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; }<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; @SuppressWarnings(\u00abunchecked\u00bb)<\/div>\n<div style=\"text-align: justify;\">private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/div>\n<div style=\"text-align: justify;\"><span style=\"color: red; font-size: large;\">&nbsp; &nbsp; &nbsp; &nbsp; new ventana2(this, true).setVisible(true);<\/span><\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; }<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp;public static void main(String args[]) {<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; \/* Create and display the form *\/<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; java.awt.EventQueue.invokeLater(new Runnable() {<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void run() {<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new ventanaPrincipal().setVisible(true);<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; });<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; }<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; \/\/ Variables declaration &#8211; do not modify &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; private javax.swing.JButton jButton2;<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; private javax.swing.JPanel jPanel1;<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; \/\/ End of variables declaration &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/div>\n<div style=\"text-align: justify;\">}<\/div>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/3.bp.blogspot.com\/-kkzCbc3VXNU\/U5cacG3t_YI\/AAAAAAAAAE8\/V33jdaPHPjI\/s1600\/Captura+de+pantalla+de+2014-06-10+09:46:12.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/-kkzCbc3VXNU\/U5cacG3t_YI\/AAAAAAAAAE8\/V33jdaPHPjI\/s1600\/Captura+de+pantalla+de+2014-06-10+09:46:12.png\" height=\"320\" width=\"400\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\">En la ventana principal, s\u00f3lo agregu\u00e9 un panel, y un bot\u00f3n en el evento de clic en el bot\u00f3n agregu\u00e9 el siguiente c\u00f3digo. &nbsp;<span style=\"color: red; font-size: large; text-align: justify;\">new ventana2(this, true).setVisible(true);<\/span><\/div>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">\/*c\u00f3digo para el jframe ventana2*\/<\/div>\n<div style=\"text-align: justify;\">package ventana;<\/div>\n<div style=\"text-align: justify;\">public class ventana2 extends javax.swing.JDialog {<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; public ventana2(java.awt.Frame parent, boolean modal) {<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; super(parent, modal);<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; setLocationRelativeTo(null);<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; &nbsp; &nbsp; initComponents();<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; }<\/div>\n<div style=\"text-align: justify;\"><span style=\"color: red; font-size: large;\">private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"color: red; font-size: large;\">&nbsp; &nbsp; &nbsp; &nbsp; System.exit(0);<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"color: red; font-size: large;\">&nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"color: red; font-size: large;\"><br \/><\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"color: red; font-size: large;\">&nbsp; &nbsp; private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"color: red; font-size: large;\">&nbsp; &nbsp; &nbsp; &nbsp; this.dispose();<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"color: red; font-size: large;\">&nbsp; &nbsp; }&nbsp;<\/span><\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; \/\/ Variables declaration &#8211; do not modify &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; private javax.swing.JButton jButton1;<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; private javax.swing.JButton jButton2;<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; private javax.swing.JLabel jLabel1;<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; private javax.swing.JPanel jPanel1;<\/div>\n<div style=\"text-align: justify;\">&nbsp; &nbsp; \/\/ End of variables declaration &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/div>\n<div style=\"text-align: justify;\">}<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/4.bp.blogspot.com\/-HjiCloYBDks\/U5ccZF8XNZI\/AAAAAAAAAFE\/6XxXzfyE4dE\/s1600\/Captura+de+pantalla+de+2014-06-10+09:51:24.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/4.bp.blogspot.com\/-HjiCloYBDks\/U5ccZF8XNZI\/AAAAAAAAAFE\/6XxXzfyE4dE\/s1600\/Captura+de+pantalla+de+2014-06-10+09:51:24.png\" height=\"305\" width=\"400\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\">En el jdialoge agregu\u00e9 un jpanel, jlabel y dos jbuttons, en los jbutos se agreg\u00f3 lo sguiente<\/div>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Y pues eso es todo. Si tienen dudas dejen sus comentarios<\/div>\n","protected":false},"excerpt":{"rendered":"<p>En uno de mis proyectos de IHC necesitaba crear un mensaje de di\u00e1logo personalizado. Dicho mensaje deb\u00eda ser enviado a pantalla y desactivar la opci\u00f3n de que el usuario pudiera dar clic o hacer cambios a la ventana desde la que se invocaba dicho mensaje de dialogo. Una opci\u00f3n era utilizar joptionpane, pero no pod\u00eda [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,87,446,1523,1521,4,1524],"tags":[],"class_list":["post-1857","post","type-post","status-publish","format-standard","hentry","category-fedora","category-gnome","category-java","category-jdialog","category-jframe","category-linux","category-timer"],"_links":{"self":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts\/1857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/comments?post=1857"}],"version-history":[{"count":0,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts\/1857\/revisions"}],"wp:attachment":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/media?parent=1857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/categories?post=1857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/tags?post=1857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}