JTabbedPane and JTextField

Using JDK 1.4.
I have created an Applet with using a JTabbedPlane with 2 tab components both are JPanels. The first-tab JPanel has a number of JTextComponents on it, the second-tab JPanel ans several JLabels, JButtons, and JTextFields.
When the Applet starts only the components on first-tab are shown - as expected.
I have created a separate class that extends JPanel (add-on-panel) that includes a number of JLabels and JTextFields that are laid out on it. If I add add-on-panel to the second-tab JPanel, add-on-panel's JTextFields show through the first-tab JPanel. Once the second-tab is selected and then the first-tab is selected, add-on-panel's JTextFields no longer show through.
I have explicity setOpaque(true) on first-tab and its components.
Is this a bug or have I messed setting up something correctly???
I have also added a third-tab JPanel that has a JTextEditor and it does not show through.
Thanks in advance

more info here (scroll down to evaluation section)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5089436

Similar Messages

  • Problem with PropertyChangeListener and JTextField

    I'm having a problem with PropertyChangeListener and JTextField.
    I can not seem to get the propertychange event to fire.
    Anyone have any idea why the code below doesn't work?
    * NewJFrame.java
    * Created on May 15, 2005, 4:21 PM
    import java.beans.*;
    import javax.swing.*;
    * @author wolfgray
    public class NewJFrame extends javax.swing.JFrame
    implements PropertyChangeListener {
    /** Creates new form NewJFrame */
    public NewJFrame() {
    initComponents();
    jTextField1.addPropertyChangeListener( this );
    public void propertyChange(PropertyChangeEvent e) {
    System.out.println(e);
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    jTextField1 = new javax.swing.JTextField();
    jScrollPane1 = new javax.swing.JScrollPane();
    jFormattedTextField1 = new javax.swing.JFormattedTextField();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTextField1.setText("jTextField1");
    getContentPane().add(jTextField1, java.awt.BorderLayout.NORTH);
    jFormattedTextField1.setText("jFormattedTextField1");
    jScrollPane1.setViewportView(jFormattedTextField1);
    getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
    pack();
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new NewJFrame().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration
    }

    If you want to listen to changes in the textfield's contents you should use a DocumentListener and not a PropertyChangeListener:
    http://java.sun.com/docs/books/tutorial/uiswing/events/documentlistener.html
    And please use [co[/i]de]  tags when you are posting code (press the code button above the message window).

  • JTabbedPane and InsertTab method

    Hi at all!!!Sorry for my bad english!!
    For a university project I want to implement a copy of notepad. Only I want to manage a more document and I think that it is possible through the JTabbedPane and it works.
    But I don't know how I can implement a button that add/remove a tab during the runtime.
    Is there someone that can help me???
    thank u
    giuliano

    Your main window should have [AddNewTab] and [RemoveTab] buttons.
    In their event handler, launch a dialog and accept required user inputs.
    After you dispose the dialog, call JTabbedPane#add(), addTab() or remove().

  • JTabbedPane and removeTabAt() method

    Hello,
    I use in my application a JTabbedPane and i want allow the user to remove a tab of this JTabbedPane. When the JTabbedPane change i need to perform some traitement.
    So i use a ChangeListener to be informed of all changes of my JTabbedPane.
    But, when i removed a tab which is not in last or first position i'm not informed by the change.
    Thanks for your help.
    Guiguch

    I had the same problem. I fixed it by overriding the remove() method to fire a StateChanged event:
    tabbedPane = new JTabbedPane()
         public void remove(int tab)
              super.remove( tab );
              int after = getSelectedIndex();
              //  The selected tab remained the same after this remove, consider
              //  it a state changed
              if (after == tab)
                   fireStateChanged();
    };

  • JChecjBox and JTextField Event Handling in JTable

    Hi,
    I am creating a dynamic Jtable from data in Database. My table has x num of rows and 5 cols. I have 2 editable columns in Table. one is of type checkbox and other is textfield. I have also created a CustomTableModel which extends DefaultTableModel. My Question is How to trap an even on JCheckBox and JTextField when User changes the data in the table. I want trap the event, read the new data and save it to the database.
    Please help me with this problem.
    I am fairly new at JTable..Please help me. Do i need to create customeCellEditor??
    Thank you.

    Thank you for your help. From TableChanged event I can find out that table has been updated. But how do i know which rows were updated? I mean How do i know which checkbox was checked/unchecked, or JTextfield text was changed? I need to read them one by one and compare with previous data. TO do that Do i need customCellEditor? Editable Checkbox is in first col of table and Editable Jtextfield is in 4th col. Number of rows vary depending on my resultset from DB.
    Please help me.
    Thank you in Advance.

  • JMenuItem and JTextField doesn't look right after upgrading to Java 8

    I just upgraded to JDK 8u25
    I have a legacy Swing application, which makes use of JMenuItem and JTextField
    I realize, after upgrading, there is a bolder grey vertical border at the left side of JMenuItem and JTextField
    JMenuItem
    JTextField
    This only happen, if I were using look n feel com.sun.java.swing.plaf.windows.WindowsLookAndFeel
    Before that, I never have such problem. Anyone know is there any workaround for such problem?
    Here's the code example to demonstrate the problem.
    package javaapplication5;
    * @author yccheok
    public class NewJFrame extends javax.swing.JFrame {
         * Creates new form NewJFrame
        public NewJFrame() {
            initComponents();
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            jTextField1 = new javax.swing.JTextField();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            jMenu2 = new javax.swing.JMenu();
            jMenuItem1 = new javax.swing.JMenuItem();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jMenu1.setText("File");
            jMenuBar1.add(jMenu1);
            jMenu2.setText("Edit");
            jMenuItem1.setText("jMenuItem1");
            jMenu2.add(jMenuItem1);
            jMenuBar1.add(jMenu2);
            setJMenuBar(jMenuBar1);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(21, 21, 21)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(232, Short.MAX_VALUE))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(19, 19, 19)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(230, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
         * @param args the command line arguments
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Windows".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            //</editor-fold>
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JMenuItem jMenuItem1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                  
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            //</editor-fold>
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JMenuItem jMenuItem1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                  

    The site looks OK -- actually quite impressive for what appears to be a from-scratch design.
    In Opera 10 under Snow Leopard 10.6.1, the design doesn't start to explode until the horizontally scrolling marquee comes across. I would strongly recommend just removing that marquee; it is an extremely outdated element of web design. If you do that, the design shouldn't blow up on you in other browsers.

  • Layout of JLabels and JTextFields

    Hi!
    I am looking for an easy way to layout JLabels and JTextFields side by side like this:
    jlabel             jtextField
    small jlabel       jtextField
    longer jlabel      jtextFieldAny ideas on how to do this?
    Peter

    Read this section from the Swing tutorial on "Using Layout Managers":
    http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
    The easiest way is to use a GridLayout.
    JPanel panel = new JPanel();
    panel.setLayout( new GridLayout(0, 2) );
    panel.add( new JLabel("...") );
    panel.add( new JTextField(10) );
    panel.add( new JLabel("...") );
    panel.add( new JTextField(10) );
    A more complicated, but more flexible way is to use a GridBagLayout. Something like this:
    public class ActivityPanel extends JPanel
         public ActivityPanel()
              setBorder( new EmptyBorder(5, 5, 5, 5) );
              setLayout( new GridBagLayout() );
              GridBagConstraints gbc = new GridBagConstraints();
              gbc.insets = new Insets(5, 10, 5, 10);
              // add street
              JLabel lStreet = new JLabel("Street");
              JTextField cStreet = new JTextField(32);
              addRow(gbc, lStreet, cStreet);
              // add city
              JLabel lCity = new JLabel("City");
              JTextField cCity = new JTextField(32);
              addRow(gbc, lCity, cCity);
         private void addRow(GridBagConstraints gbc, Component left, Component right)
              gbc.gridx = GridBagConstraints.RELATIVE;
              gbc.gridy = GridBagConstraints.RELATIVE;
              gbc.gridheight = 1;
              gbc.gridwidth = 1;
              gbc.anchor = GridBagConstraints.EAST;
              add(left, gbc);
              gbc.gridwidth = GridBagConstraints.REMAINDER;
              gbc.anchor = GridBagConstraints.WEST;
              add(right, gbc);
    }

  • Align JLabels and JTextFields vertically in different areas

    I like to have 3 TitledBorders for 3 different areas of my frame.
    Each area has its own components - JLabels, JTextField, etc.
    How to align JLabels and JTextFields vertically in different areas?
    e.g. for the following test program, how to configure label1, label2, label3 so that their right sides all align vertically and
    tf1, tf2, tf3 so that their left sides all align vertically?
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.GridLayout;
    import java.awt.Insets;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.border.TitledBorder;
    public class TitledBorderDemo extends JFrame {
      public TitledBorderDemo() {
        super("TitledBorderDemo");
        JTextField tf1 = new JTextField("hello", 6);
        JTextField tf2 = new JTextField("hello", 12);
        JTextField tf3 = new JTextField("test");
        JTextField tf4 = new JTextField("test2");
        JLabel label1 = new JLabel("1234567890ertyuiyup label");
        JLabel label2 = new JLabel("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz long label");
        JLabel label3 = new JLabel("short label");
        JLabel label4 = new JLabel("test");
        JPanel panel_tf = new JPanel(new GridBagLayout());
        JPanel panel_pf = new JPanel(new GridBagLayout());
        JPanel panel_ftf = new JPanel(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints(0, 0, 3, 3,
                0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(10, 10, 10, 10), 0, 0);
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.gridwidth = 2;
        constraints.anchor = GridBagConstraints.WEST;
        panel_tf.add(label1, constraints);
        constraints.gridx = 2;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        panel_tf.add(tf1, constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.gridwidth = 2;
        constraints.anchor = GridBagConstraints.WEST;
        panel_pf.add(label2, constraints);
        constraints.gridx = 2;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        panel_pf.add(tf2, constraints);
        constraints.gridx = 0;
        constraints.gridy = 2;
        constraints.gridwidth = 2;
        constraints.anchor = GridBagConstraints.WEST;
        panel_ftf.add(label3, constraints);
        constraints.gridx = 2;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        panel_ftf.add(tf3, constraints);
        constraints.gridx = 3;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.WEST;
        panel_ftf.add(label4, constraints);
        constraints.gridx = 4;
        constraints.anchor = GridBagConstraints.EAST;
        panel_ftf.add(tf4, constraints);
        panel_tf.setBorder(new TitledBorder("JTextField1"));
        panel_pf.setBorder(new TitledBorder("JTextField2"));
        panel_ftf.setBorder(new TitledBorder("JTextField3"));
        JPanel pan = new JPanel(new GridLayout(3, 1, 10, 10));
        pan.add(panel_tf);
        pan.add(panel_pf);
        pan.add(panel_ftf);
        this.add(pan);
      public static void main(String args[]) {
        JFrame frame = new TitledBorderDemo();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600, 450);
        frame.setVisible(true);
    }

    Thank you! It works!
    I add some labels & components to your demo program.
    Most of the components align vertically.
    How to align the "Country", "Test2" & "Extension" labels on the right sides?
    How to align their corresponding components so that their left sides all align vertically?
    How to make the Cancel button stick to the Save button
    (i.e. eliminate the gap between the Cancel and the Save button)?
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class TitledBorderDemoNew extends JFrame {
      public TitledBorderDemoNew() {
        super("TitledBorderDemoNew");
        JLabel nameLabel = new JLabel("Name");
        JTextField nameText = new JTextField(20);
        JLabel addressLabel = new JLabel("Address (City & State)");
        JTextField addressText = new JTextField(40);
        JLabel countryLabel = new JLabel("Country");
        JTextField countryText = new JTextField(30);
        JLabel testLabel = new JLabel("Test");
        JTextField testText = new JTextField(20);   
        JLabel test2Label = new JLabel("Test2");
        JTextField test2Text = new JTextField(20);   
        JLabel phoneLabel = new JLabel("Phone");
        JTextField phoneText = new JTextField(20);
        JLabel extensionLabel = new JLabel("Extension");
        JTextField extensionText = new JTextField(5);
        JLabel postalCodeLabel = new JLabel("Postal Code");
        JTextField postalCodeText = new JTextField(6);
        JButton saveButton = new JButton("Save");
        JButton cancelButton = new JButton("Cancel");
        JButton commentButton = new JButton("Comment");
        int longWidth = addressLabel.getPreferredSize().width;
        GridBagConstraints constraints = new GridBagConstraints();
        JPanel p1 = new JPanel(new GridBagLayout());
        p1.setBorder(createBorder("Name"));
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p1.add(nameLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p1.add(nameText, constraints);
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p1.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.fill = GridBagConstraints.NONE;
        constraints.weightx = 0.0;
        p1.add(Box.createHorizontalStrut(longWidth), constraints);
        JPanel p2 = new JPanel(new GridBagLayout());
        p2.setBorder(createBorder("Address"));
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p2.add(addressLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p2.add(addressText, constraints);
        // extra label & component
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,36,4,6);
        p2.add(countryLabel, constraints);
        constraints.gridx = 3;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.insets = new Insets(4,6,4,6);
        p2.add(countryText, constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p2.add(testLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p2.add(testText, constraints);
        // extra label & component
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,36,4,6);
        p2.add(test2Label, constraints);
        constraints.gridx = 3;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.insets = new Insets(4,6,4,6);
        p2.add(test2Text, constraints);
        constraints.gridx = 4;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p2.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 0;
        constraints.gridy = 2;
        constraints.fill = GridBagConstraints.NONE;
        constraints.weightx = 0.0;
        p2.add(Box.createHorizontalStrut(longWidth), constraints);
        JPanel p3 = new JPanel(new GridBagLayout());
        p3.setBorder(createBorder("Phone"));
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p3.add(phoneLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p3.add(phoneText, constraints);
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p3.add(extensionLabel, constraints);
        constraints.gridx = 3;
        constraints.anchor = GridBagConstraints.WEST;
        p3.add(extensionText, constraints);
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p3.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.fill = GridBagConstraints.NONE;
        constraints.weightx = 0.0;
        p3.add(Box.createHorizontalStrut(longWidth), constraints);
        JPanel p4 = new JPanel(new GridBagLayout());
        p4.setBorder(createBorder("Postal Code"));
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p4.add(postalCodeLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p4.add(postalCodeText, constraints);
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p4.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.fill = GridBagConstraints.NONE;
        constraints.weightx = 0.0;
        p4.add(Box.createHorizontalStrut(longWidth), constraints);
        JPanel p5 = new JPanel(new GridBagLayout());
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.insets = new Insets(4,6,4,6);
        p5.add(commentButton, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p5.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 2;
        constraints.gridwidth = GridBagConstraints.RELATIVE;
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor = GridBagConstraints.EAST;
        p5.add(cancelButton, constraints);
        constraints.gridx = 3;
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.anchor = GridBagConstraints.EAST;
        p5.add(saveButton, constraints);
        JPanel panel = new JPanel(new GridBagLayout());
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        panel.add(p1, constraints);
        constraints.gridy = 1;
        panel.add(p2, constraints);
        constraints.gridy = 2;
        panel.add(p3, constraints);
        constraints.gridy = 3;
        panel.add(p4, constraints);
        constraints.gridy = 4;
        panel.add(p5, constraints);
        this.add(new JScrollPane(panel));
      private Border createBorder(String title)
        TitledBorder b = new TitledBorder(title);
        b.setTitleColor(Color.RED.darker());
        return b;
      public static void main(String args[]) {
        JFrame frame = new TitledBorderDemoNew();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }Edited by: 833768 on 26-Apr-2011 10:32 AM

  • JTabbedPane and focus problem.

    Hello. I currently have a JTabbedPane which contains the various panels that make up different tabs. These tabs are extensions of panels, and are seperate classes imported into the class which contains my JTabbedPane and then added. The frame which conatins my JTabbedPane also has a button, which when pressed I wish it to look at the tab which is currently active, and call a method from the class which this tab refers to. The problem is that I don't know how to get my button to determine which tab is currently active. Any help will be gratefully recieved.

    Use getSelectedComponent() or getSelectedIndex() of your JTabbedPane object.

  • JTabbedPane and one Button for all Tabs

    Hello everybody,
    im new here an would say HELLOOO to everyone
    So ive got an issue.
    I am creating in "class A"  tabs for a JTabbedPane. In "class B" i create the JTabbedPane and creat instances of class A and add them to the TabbedPane.
    in Class B i also create a button, for save actions. When i click the button, a method "save()" will be called and read from every tab the Strings out of textfields.
    My problem now is, that it dont work, i call the save method with the instance from the tab, but it dont getText() from the textfield.
    For example:
    //create an instance tab, parameter is the save file
    Tab myTab = new Tab(file);
         //other code
    (Tab)myTab.save(); //here i eclipse cast to Tab automatically
    the save-Method in class A (Tab):
    save() {
    sysout(texfield1.getText)
    BTW how can i highlight code in this forum?

    You can add syntax highlighting by going into the advanced editor, that will add a button for it. Unfortunately there are no quick code tags :/
    After you find the button post your ACTUAL code. not just some random snippet which looks like your code. What you posted doesn't even compile.

  • JTabbedPane, and JPanel.

    Hi im going thrue swing tutorials here on sun. And wonder a bit about hierarchy. I use JTabbedPane and every class have there own JPanel that i add to the extended JPanel. I show below with example.
    In Main class
      public JFrame mstFrame() {
            JFrame frame = new JFrame("Main Frame");
            JTabbedPane mstPane = new JTabbedPane();
            mstPane.addTab("Start", new StartPage());
            frame.add(mstPane);
            frame.setVisible(true);
            return frame;
        }In StartPage Class
    public class StartPage extends JPanel {
        JPanel createProjectPanel = new JPanel(new GridBagLayout());
         GridBagConstraints c = new GridBagConstraints();
         JScrollPane createCustomerPane = new JScrollPane();
         c.gridy = 1; // second row
         c.gridx = 0; // first cell
         createProjectPanel.add(createCustomerPane ,c);
    add(createProjectPanel);Does this destory the hierarchy, or is it okey to do it this way?

    It makes sense to have each tab represented by a panel, so I don't reallly understand the question.
    public class StartPage extends JPanel
        JPanel createProjectPanel = new JPanel(new GridBagLayout());
        add( createProjectPanel );However, it is unecessary to create a second panel since your class already extends JPanel. Just add the scrollPane directly to the class.
    setLayout( new GridBagLayout() ):
    JScrollPane createCustomerPane = new JScrollPane();
    add(createCustomerPane, c);

  • Help with JLabels and JTextFields

    I'm experimenting with JLabels and JTextFields in a basic JFrame. What I am trying to accomplish (without success) is to align a JLabel above and centered on a JTextField. The tutorials are confusing me. Any help would be greatly appreciated. a Sample of code is ...
    JLabel  myTextLabel = new JLabel("Who's text Field?");
    JTextField myTextField = new JTextField("My Text Field");...after reading the tutorial I thought that I needed to assign L&F variables to the JLabel ... i.e.
    JLabel myTextLabel = new JLabel("Who's text field?:", JLabel.CENTER, JLabel.TOP); but this results in an error when compiling. (cannot find symbol), so I thought I need to assign the JLabel to the JTextField. i.e.
    myTextLabel.setLabelFor(myTextField);Then I get "identifier" expected. So now being completely confused I am here asking "How do I?" :)
    Thanks in advance!

    Most likely, you need to think a little more about using a layout manager to hlp you along the way. If memory serves, the default layout manager for a JPanel is FlowLayout and that will simply place the components you add to the panel one after another and allow each to adopt it's preferred size.
    One way to ensure that the two compoenets were sized equally, would be to use the GridLayout layout manager and create either one row with two columns, or two rows with one column on each. Then add the compoennets to each of the 'cells' so to speak and that should ensure that they are both the same size.
    As to making the text centered in each, both the JLabel and JtextField classes have amethod called setHorizontalAlignment(); it can be used to aligh the text as you require.
    Simply create an instance of the class;
    JLabel aLabel = new JLabel("Some Text");
    // Then set the alignment
    aLabel.setHorizontalAlignment(SwingConstants.CENTER);Or, do the whole operation i one step
    JLabel aLabel = new JLabel("Sone Text", SwingConstants.CENTER);and then add the componenet to the panel once you have set the layout manager.
    Remember that the label.textfield will have to be wide enought to make it obvious that the text is centered!

  • Sizing issues JButton and JTextField

    Hi,
    I am new to swing and could use a little guidance on the placement of JButtons and JTextFields on a component. I have tried the setSize method and it doesn't work so I think it has to do with the layout possibly. I need to know how I can resize the testMe button and enlarge the JTextFields. Here is my code.
    I would appreciate any other suggestions as well.
    Thanks,
    Steve
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class TestButton {
        public static void main(String[] arguments) {
            JFrame frame = new Interface();
            frame.show();
    class Interface extends JFrame {
         private dataPanel screenvar;
         private JTextArea msgout;
         Interface () {
              super("This is a JFrame");
            setSize(600, 200);  // width, height
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel pane = new JPanel();
              // create empty space
              pane.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30)); //top, left, bottom, right
              // declare components
              msgout = new JTextArea( 8, 40 );
              dataPanel screenvar = new dataPanel();
              buttonPanel testMe = new buttonPanel(screenvar, msgout);
              // end declare components
            GridLayout grid = new GridLayout(1, 4, 5, 15); // row, col, hgap, vgap
            pane.setLayout(grid);
              pane.add(testMe);
              pane.add(msgout);
                 pane.add( new JScrollPane(msgout));
              pane.add(screenvar);
              msgout.append("Successful");
              setContentPane(pane);
    //          pack();
              setVisible(true);
    class databaseConnection {
    class updateDataFields implements ActionListener {     // 400
         private dataPanel abc;
         private JTextArea msg;
         public updateDataFields(dataPanel xyz, JTextArea msgout) {     // 100
              abc = xyz;
              msg = msgout;
         }     // 100
         public void actionPerformed(ActionEvent evt) {     // 200
              String command = evt.getActionCommand();
                   if (command.equals("TestMe")){     // 300
                        msg.append("\nSuccessful");
                        abc.right01.setText("1000");
                        abc.left02.setText("Hi!");
                        abc.right03.setText("123456");
                   }     // 300
         }     // 200
    }     // 400
    class dataPanel extends JPanel {     // Similar to DataPanel in Duke's Bakery
         JLabel left1, left2, left3, right1, right2, right3;
         JTextField left01, left02, left03, right01, right02, right03;
        public dataPanel () {     // 1
              GridLayout grid = new GridLayout(3, 2, 5, 15); // row, col, hgap, vgap
              setLayout(grid);                    // different than panex.setLayout(xgrid);
              left1 = new JLabel("Left1");
              add(left1);
              left01 = new JTextField(0);
              add(left01);
              right1 = new JLabel("Right1");
              add(right1);
              right01 = new JTextField(0);
              add(right01);
              left2 = new JLabel("Left2");
              add(left2);
              left02 = new JTextField(0);
              add(left02);
              right2 = new JLabel("Right2");
              add(right2);
              right02 = new JTextField(0);
              add(right02);
              left3 = new JLabel("Left3");
              add(left3);
              left03 = new JTextField(0);
              add(left03);
              right3 = new JLabel("Right3");
              add(right3);
              right03 = new JTextField(0);
              add(right03);
    class buttonPanel extends JPanel {     // 200   Similar to ButtonPanel in Duke's Bakery
         public buttonPanel(dataPanel xyz, JTextArea msgout) {     // 100
              GridLayout actionGrid = new GridLayout(1, 1, 5, 15); // row, col, hgap, vgap
              setLayout(actionGrid);                    // different than panex.setLayout(xgrid);
              JButton buttonTest = new JButton("TestMe");
              buttonTest.setSize(5,5);
              buttonTest.addActionListener( new updateDataFields( xyz, msgout ));
              add(buttonTest);
         }     // 100
    }     // 200

    Nope, doesn't work. Does the fact that the JButton is part of GridLayout have any affect on this resizing issue?
    Thanks for your help, I appreciate it.
    Steve

  • JTabbedPane with JTextField

    Can anyone provide me with an example on how to incorporate a JTextField into a JTabbedPane? There are many examples of creating JButtons as components of a JTabbedPanes but nothing for JTextFields. Can this be done? I get some wierd compiler errors when I try it?
    Any help will be much appreciated. Thanks.

    Thanks for the quick response but...
    My question was "how to incorporate these fields into a JTabbedPane."
    I'm new to Java so I have "borrowed" a Sun Tutorial JTabbedPane example which includes one JLable component per tab and tried to add a JTextField.
    Here is "my" code.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TabbedPaneDemo extends JFrame {
    // Initialize Screen Text Fields
    private JTextField lastName = null;
    //Vector recordData = new Vector(20);
    public TabbedPaneDemo() {
    ImageIcon icon = new ImageIcon("images/middle.gif");
    JTabbedPane tabbedPane = new JTabbedPane();
    Component panel1 = makeRecordPanel("Teacher Record");
    tabbedPane.addTab("Teacher", icon, panel1, "Update Teacher Information");
    tabbedPane.setSelectedIndex(0);
    Component panel2 = makeRecordPanel("Parent Record");
    tabbedPane.addTab("Parent", icon, panel2, "Update Parent Information");
    Component panel3 = makeRecordPanel("Child Record");
    tabbedPane.addTab("Child", icon, panel3, "Update Child Information");
    //Add the tabbed pane to this panel.
    setLayout(new GridLayout(1, 1));
    add(tabbedPane);
    protected Component makeRecordPanel(String text) {
    JPanel panel = new JPanel(false);
    JLabel label1 = new JLabel("Last Name");
    JTextField lastName = new JTextField(20);
    label1.setHorizontalAlignment(JLabel.LEFT);
    panel.setLayout(new GridLayout(1, 1));
    panel.add(label1);
    panel.add(lastName);
    return panel;
    public static void main(String[] args) {
    JFrame frame = new JFrame("Maintain DayCare Records");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}
    frame.getContentPane().add(new TabbedPaneDemo(),
    BorderLayout.CENTER);
    frame.setSize(800, 600);
    frame.setVisible(true);
    This compiles OK but when I try to run it I get the following run-time errors.
    java.lang.Error: Do not use TabbedPaneDemo.setLayout() use TabbedPaneDemo.getContentPane().setLayout() instead
         at javax.swing.JFrame.createRootPaneException(JFrame.java:333)
         at javax.swing.JFrame.setLayout(JFrame.java:394)
         at TabbedPaneDemo.<init>(TabbedPaneDemo.java:29)
         at TabbedPaneDemo.main(TabbedPaneDemo.java:53)
    Any thoughts?

  • JTabbedPane and Serialization

    Hi, I want to Serialize a JTabbedPane to a file but I am experiencing lots of problems :
    Firstly, I get an exception :
    java.io.NotSerializableException: javax.swing.plaf.basic.BasicTabbedPaneUI$MouseHandler
    I can override this in out custom plaf, but then this throws out pluggable look and feel. Is there any other way I can fix this ....
    Also I have had to change lots of code to get these to Serialize e.g cutomizing the BasicTabbedPaneUI and other classes to implement Serializable, and I get a bizarre problem where I write my Swing JxInternalFrame to disk, and then when I goto dispose of it, it throws a completely different Exception in firePropertyChanged within JTabbedPane.
    It tries to cast a JTabbedPane within the class BasicTabbedPaneUI$PropertyChangeHandler and the source is a Viewport... If I remove the Serialize to Disk code, then this does not occur!
    I am a little baffled why this happens ... can anyone help?

    My objective is to Serialize out the JxInternalFrame with all it's components to disk.
    We have an Application that Dynamically creates GUI interfaces using XML. Instead of creating the JxInternalFrame and all its components from the XML String, I thought it would be quicker to Serialize the Object to disk and re-read once the Frame once it had initialliy been built, for caching purposes.
    It takes about 4 seconds to build a 6MB JxInternalFrame with all its components (JTabbedPanes, JTextFields, JCombos etc....), and I want to minimise this to be almost instant ... i.e as if using JInternalFrame.setVisible( true or false ).
    I have not looked at XMLEncoder/Decoder yet, I will have a look and see if this will help or if this is fast enough.
    Bare in mind I could be opening a Screen many times, but do not want to initiate it again from raw XML AND I do not want to store Huge objects in memory.

Maybe you are looking for

  • Sequences - Test Organzer:  How to move more than 1 test case at a time

    Hello, I would like to be able to move multiple test cases within a sequence but I do not know how.  If I highlight multiple rows and select Move Test Case only 1 of the rows will move.  This is fine if your test package only has a few transactions b

  • Problem to print with HP Color LaserJet CP3525 (PCL 6) on Server

    Hi, I have a printer HP Color LaserJet CP3525 in a server, and I installed with the correct drivers for that but the printing output is strange. I'm trying to print in A4 paper, and everything is just printed in 1/4 of the page. The most strange is t

  • SRM 7 automatically assign source of supply in SOCO

    Hi guru, I'm working with SRM 7.0 extended classic scenario and i have to transfer external requirements from backend SAP into SRM Sourcing Cockpit. In the SOCO I have to determine automatically the source of supply and the price. I read that in the

  • ME57 - Assign and Process PR

    Hi Guys, I need to setup below two fileds active, when go in to TCode ME57 1. Assigned Purchase Requiesitions 2. Released Requisitions only How to setup / config settings ? Thanks, Sankaran

  • Full loads and how the tables in BW are rebuilt

    I have a question.  If i am doing full loads every time how does the underlying BW table look.  for example if I have 100 records the 1st time, then 80 what is the record count in the BW table?    does it do some sort of automatic deletion every time