/* * TabbedPaneDemo.java is a 1.4 example that requires one additional file: * images/middle.gif. */ import javax.swing.JTabbedPane; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.JComponent; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.KeyEvent; import javax.swing.*; public class TabbedPaneDemo extends JPanel { //agregadas por mi. areas de texto sin estilo. protected JTextArea antecedentesArea; protected JTextArea motivoatencionArea; protected JTextArea diagnosticoArea; protected JTextArea medicamentosArea; protected JTextArea comentariosArea; public TabbedPaneDemo() { super(new GridLayout(1, 1)); //Creación de las distintas paneles de texto con sus características respectivas antecedentesArea = new JTextArea(8,60); JScrollPane antecedentesScrollPane = new JScrollPane(antecedentesArea); antecedentesScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); motivoatencionArea = new JTextArea(8,60); JScrollPane motivoScrollPane = new JScrollPane(motivoatencionArea); motivoScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); diagnosticoArea = new JTextArea(8,60); JScrollPane diagnosticoScrollPane = new JScrollPane(diagnosticoArea); diagnosticoScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); medicamentosArea = new JTextArea(); JScrollPane medicamentosScrollPane = new JScrollPane(medicamentosArea); medicamentosScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); comentariosArea = new JTextArea(); JScrollPane comentariosScrollPane = new JScrollPane(comentariosArea); comentariosScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); //Creación del tabbedPane con sus tabs JTabbedPane tabbedPane = new JTabbedPane(); ImageIcon icon = createImageIcon("images/middle.gif"); JComponent panel1 = makeScrollPanel(antecedentesScrollPane); tabbedPane.addTab("Antecedentes", icon, panel1, "Antecedentes Clínicos"); tabbedPane.setMnemonicAt(0, KeyEvent.VK_A); JComponent panel2 = makeScrollPanel(motivoScrollPane); tabbedPane.addTab("Cuadro Clínico", icon, panel2, "Cuadro Clínico"); tabbedPane.setMnemonicAt(1, KeyEvent.VK_U); JComponent panel3 = makeScrollPanel(diagnosticoScrollPane); tabbedPane.addTab("Diagnóstico", icon, panel3, "Diagnósticos y avances"); tabbedPane.setMnemonicAt(2, KeyEvent.VK_D); JComponent panel4 = makeScrollPanel(medicamentosScrollPane); tabbedPane.addTab("Tratamiento", icon, panel4, "Medicamentos recetados"); tabbedPane.setMnemonicAt(3, KeyEvent.VK_M); JComponent panel5 = makeScrollPanel(comentariosScrollPane); tabbedPane.addTab("Comentarios", icon, panel5, "Comentarios"); tabbedPane.setMnemonicAt(4, KeyEvent.VK_C); //Add the tabbed pane to this panel. add(tabbedPane); //Uncomment the following line to use scrolling tabs. tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); } //Convierte el scrollPane en un componente (panel) normal protected JComponent makeScrollPanel(JScrollPane pane) { JPanel panel = new JPanel(false); panel.setLayout(new GridLayout(1, 1)); panel.add(pane); return panel; } /** Returns an ImageIcon, or null if the path was invalid. */ protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = TabbedPaneDemo.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } }