JTable in JPanel in JTabbedPane in JScrollPane in JSplitPane problem

I have a JSplitPane with a divider in the center; of which the top is a JPanel and the bottom is a JScrollPane that contains a JTabbedPane, for which each tab contains a JPanel which contains a JTable.
When I move the divider up, so that it now takes up 75% of the JSplitPane, the JScrollPane and the JTabbedPane expand with the JSplitPane, but the JPanel that contains the JTable remains the same size that it had at the beginning.
What I would like to see is more rows of the JTable as I move the divider to give the JScrollPane more room.
Is there an easy way to keep all of the J components sizes in sync as the JSplitPane gets larger or smaller ? (JDK 1.3.1)

Hi,
The JPanels which you have inside each tab of the JTabbedPanes should have BorderLayout and the JScrollPanes which hold the JTables should be added with the BorderLayout.CENTER constraint. This will make sure that the JScrollPanes that contain the JTables occupy as much space as possible.
Hope this helps,
Ranga.

Similar Messages

  • JTable on JPanel

    I have a JTable that used to have a header on a JScrollPane, until i placed the table onto a JPanel. The header of my table suddenly disappeared, just the contents of my rows remain....does anyone know why?

    If you don't put the table in a scrollpane, you have to place the header yourself.import java.awt.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        content.setLayout(new GridLayout(1,2));
        String[] head1 = {"One","Two","Three"}, head2={"Uno","Dos","Tres"};
        String[][] data1 = new String[10][head1.length], data2=new String[10][head2.length];
        for (int i=0; i<data1.length; i++) {
          for (int j = 0; j < data1.length; j++) data1[i][j] = "R" + i + "-C" + j;
    for (int i=0; i<data2.length; i++) {
    for (int j = 0; j < data2[i].length; j++) data2[i][j] = "F" + i + "-C" + j;
    JTable jt1 = new JTable(data1,head1), jt2 = new JTable(data2, head2);
    content.add(new JScrollPane(jt1));
    JPanel jp2 = new JPanel(new BorderLayout());
    jp2.add(jt2, BorderLayout.CENTER);
    jp2.add(jt2.getTableHeader(), BorderLayout.NORTH);
    content.add(jp2);
    setSize(600,300);
    setVisible(true);
    public static void main(String[] args) { new Test3(); }

  • About JPanel and JTabbedPane

    I have a JPanel and i want to know how any tab buttons it contain.
    We have a method in JTabbedPane to find it out ,so how can i type cast the JPanel to JTabbedPane.
    Thanks

    JTabbedPane does not extend JPanel, so you can't cast JPanel to JTabbedPane.
    A JPanel does not contain any tabs.
    I think you might need to rephrase the question.

  • JTable in JPanel last Column resize clips JTable doesnt repaint JPanel

    I have a JTable in a JPanel, when I drag the last column of the JTableHeader (u can see the column resizing as the text of the Table HeaderColumn moves with the drag) the JTable is outside the JPanel. Only when u click on another component and then click back on the JTableHeader does it repaint.
    I have tried jPanel.revalidate(); in the mouseDragged event of MouseMotionListener on the JTableHeader and all manner or repaints and fireTableStructureChanged. But I dont understand the order of events.
    The last bug to fix!!!
    NB I dont want to use scrollpane as its not necessary and as many tables are synchronized with one table it makes repaints less smooth
    Thanks Paul

    Well, I didn't find an answer but I did find a solution.
    The JPanel is the problem. I use it to help with layout which is not obvious in this example.
    As you can see in the code the JTable is placed in a JScrollPane which is place in a JPanel which is placed in a JTabbedPane.
    If I use Box instead of JPanel the JTable in the JScrollPane in the Box in the TabbedPane in the JFrame resizes correclty.
    So although JPanel is resizable with setSize it does not get resized when it's JFrame gets resized.
    I would still like to know why?
    ////////KBS
    JTabbedPane myTP = new JTabbedPane();
    Box myOne = Box.createHorizontalBox();
    Box myTwo = Box.createHorizontalBox();
    myOne.add(pane);
    myTP.add("One", myOne);
    myTP.add("Two", myTwo);
    ////////KBS

  • JTable, JScrollPane, and JinternalFrame problems.

    I have this internal frame in my application that has a scrollpane and table in it. Some how it won't let me selelct anything in the table. Also it scrolls really weird. There's a lot of chopping going on. Here's my code for the internal frame:
    public class BCDEObjectWindow extends javax.swing.JInternalFrame{
        private Vector bcdeObjects = new Vector();
        private DefaultTableModel tModel;
        public BCDEObjectWindow(JavaDrawApp p) {
            initComponents();
            this.setMaximizable(false);
            this.setClosable(false);
            this.setIconifiable(true);
            this.setDoubleBuffered(true);
            objectTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
            listScrollPane.setColumnHeaderView(new ObjectWindowHeader());
            pack();
            this.setVisible(true);
            parent = p;
            getAllBCDEFigures();
            setPopupMenu();
            tModel = (DefaultTableModel) objectTable.getModel();
            objectTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        public void getAllBCDEFigures() {
            bcdeObjects.removeAllElements();
            int i;
            for (i = 0; i < bcdeObjects.size(); i++) {
                tModel.removeRow(0);
        public void addBCDEFigure(BCDEFigure b) {
            bcdeObjects.add(b);
            tModel.addRow(new Object[]{b.BCDEName, "incomplete"});
        public void changeLabelName(BCDEFigure b) {
            if (bcdeObjects.contains(b)) {
                int index = bcdeObjects.indexOf(b);
                tModel.removeRow(index);
                tModel.insertRow(index, new Object[]{b.BCDEName, "incomplete"});
        public void removeBCDEFigure(BCDEFigure b) {
            int index = 0;
            if (bcdeObjects.contains(b)) {
                index = bcdeObjects.indexOf(b);
                bcdeObjects.remove(b);
                tModel.removeRow(index);
        public void removeAllBCDEFigures(){
            int i;
            for (i = 0; i < bcdeObjects.size(); i++) {
                tModel.removeRow(0);
            bcdeObjects.removeAllElements();
        /** 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.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            listScrollPane = new javax.swing.JScrollPane();
            objectTable = new javax.swing.JTable();
            getContentPane().setLayout(new java.awt.FlowLayout());
            setBackground(new java.awt.Color(255, 255, 255));
            setIconifiable(true);
            setTitle("BCDE Objects");
            listScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            listScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            listScrollPane.setPreferredSize(new java.awt.Dimension(250, 150));
            objectTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                new String [] {
                    "Name", "Status"
                boolean[] canEdit = new boolean [] {
                    true, false
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
            objectTable.setColumnSelectionAllowed(true);
            listScrollPane.setViewportView(objectTable);
            jPanel1.add(listScrollPane);
            getContentPane().add(jPanel1);
            pack();
        }// </editor-fold>
        // Variables declaration - do not modify
        private javax.swing.JPanel jPanel1;
        private javax.swing.JScrollPane listScrollPane;
        private javax.swing.JTable objectTable;
        // End of variables declaration
    }and this is how i create the object in my JFrame:
    bcdeOW = new BCDEObjectWindow(this);
            bcdeOW.setLocation(400, 0);
            if (getDesktop() instanceof JDesktopPane) {
                ((JDesktopPane)getDesktop()).setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
                ((JDesktopPane)getDesktop()).add(bcdeOW, JLayeredPane.PALETTE_LAYER);
            } else
                getDesktop().add(bcdeOW);Any help would be great. Thanks a lot.

    Rajb1 wrote:
    to get the table name to appear
    create a scollpane and put the table in the scrollpane and then add the the scollpane to the component:
    //declare
    scrollpane x;
    //body code
    scrollpane x - new scrollpane();
    table y = new table();
    getContentPane().add(x(y));What language is this in, the lambda calculus -- add(x(y))!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Problem with JTable and JPanel

    Hi,
    I'm having problems with a JTable in a JPanel. The code is basicly as follows:
    public class mainFrame extends JFrame
            public mainFrame()
                    //A menu is implemeted giving rise to the following actions:
                    public void actionPerformed(ActionEvent evt)
                            String arg = evt.getActionCommand();
                            if(arg.equals("Sit1"))
                            //cells, columnNames are initiated correctly
                            JTable table = new JTable(cells,columnNames);
                            JPanel holdingPanel = new JPanel();
                            holdingPanel.setLayout( new BorderLayout() );
                            JScrollPane scrollPane = new JScrollPane(holdingPanel);
                            holdingPanel.setBackground(Color.white);
                            holdingPanel.add(table,BorderLayout.CENTER);
                            add(scrollPane, "Center");
                            if(arg.equals("Sit2"))
                                    if(scrollPane !=null)
                                            remove(scrollPane);validate();System.out.println("ScrollPane");
                                    if(holdingPanel !=null)
                                            remove(holdingPanel);
                                    if(table !=null)
                                            remove(table);table.setVisible(false);System.out.println("table");
                            //Put other things on the holdingPanel....
            private JScrollPane scrollPane;
            private JPanel holdingPanel;
            private JTable table;
    }The problem is that the table isn't removed. When you choose another situation ( say Sit2), at first the table apparently is gone, but when you press with the mouse in the area it appeared earlier, it appears again. How do I succesfully remove the table from the panel? Removing the panel doesn't seem to be enough. Help is much appreciated...
    Best regards
    Schwartz

    If you reuse the panel and scroll pane throughout the application,
    instantiate them in the constructor, not in an often-called event
    handler. In the event handler, you only do add/remove of the table
    on to the panel. You can't remove the table from the container
    which does not directly contain it.
    if (arg.equals("Sit2")){
      holdingPanel.remove(table);
      holdingPanel.revalidate();
      holdingPanel.repaint(); //sometimes necessary
    }

  • JTable in JPanel cut off

    I'm trying to put a JTable with several elements in a JPanel and it is getting cut off. I have tried extending the gridbagconstraints with ipady but no luck.
    public class PumpMonitor extends JPanel
    JTable Table1;
    PumpMonitor()
    Table1Model dm = new Table1Model();
    Table1 = new JTable( dm ) ;
    GridBagLayout gridBagLayout3 = new GridBagLayout();
    gridBagLayout3.rowHeights[0] = 300;
    Dimension size = new Dimension(300,400);
    this.setMinimumSize(size);
    this.setVisible(true);
    this.setPreferredSize(size);
    this.setMaximumSize(size);
    this.setLayout(gridBagLayout3);
    Table1.setBackground(Color.white);
    Table1.setEnabled(false);
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 1;
    c.ipady = 10;
    c.gridwidth = 100;
    c.anchor = GridBagConstraints.NORTHWEST;
    gridBagLayout3.setConstraints(hel,c);
    this.add(hel);
    this.add(Table1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 74, 500));
    class Table1Model extends AbstractTableModel
    Object[][] Table1Data =
    {"Address",new String()},
    {"Serial #" ,new String()},
    {"SW Revision" ,new String()},
    {"ETM" ,new String()},
    {"T1",new String()},
    {"T2" ,new String()},
    {"TC/Vac Gauge" ,new String()},
    {"Aux TC" ,new String()},
    {"Motor Speed",new String()},
    {"Set Values" ,new String()},
    {"Heater Pwr T1" ,new String()},
    {"Heater Pwr T2" ,new String()},
    public void setValueAt (Object value, int row, int col)
         Table1Data[row][col] = value;
         public int getColumnCount()
    return Table1Data[0].length;
    public int getRowCount()
    return Table1Data.length;
    /* public String getColumnName(int col)
    return (String)headers[col];
    public Object getValueAt(int row,int col)
    return Table1Data[row][col];
    };

    Thanks Denis.
    I did this:
    JScrollPane scroll = new JScrollPane(Table1);
    this.add(scroll, new GridBagConstraints(0, 0, 1, 3, 1.0, 1.0
    ,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 74, 500));
    That works but I want to see the whole table at once. Is there something I can do to do that?

  • JTabbedPane with JScrollPane

    The application uses a JTabbedPane, each Tab contains a JScrollPane, the TopComponent contains the same Class with different Classes for the BottomComponent. Each BottomComponent is a separate class and relates to a different table. How can I interface with with the other classes without knowing which Tab is active?

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Property_Features extends JPanel implements ActionListener{
         private JTextArea txtFeature;
         private JLabel image;
         private JButton btnNew = null;
         private JButton btnUpd = null;
         private JButton btnDel = null;
         private JToolTip toolTip = null;
         private Prop_Header propHdr = null;
         private JPanel fPanel = null;
         private JPanel wPanel = null;
         private Box vertBox;     
         private Box topBox;     
         private Box midBox;     
         private Box botBox;     
    public Property_Features(){
         toolTip = new JToolTip();
         vertBox = Box.createVerticalBox();
         topBox = Box.createHorizontalBox();
         midBox = Box.createHorizontalBox();
         botBox = Box.createHorizontalBox();
         wPanel = new JPanel();
         wPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         txtFeature = new JTextArea(5,50);
         txtFeature.setFont(new Font("SansSerif", Font.PLAIN, 14));
         txtFeature.setLineWrap(true);
         txtFeature.setWrapStyleWord(true);
         txtFeature.setEditable(true);
         txtFeature.setBorder(BorderFactory.createTitledBorder(" Describe the Property Features"));
         toolTip.setComponent(txtFeature);
         txtFeature.setToolTipText("Enter Property Feature of Major Interest");
         wPanel.add(txtFeature);
         topBox.add(wPanel);
         wPanel = new JPanel();
         wPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         btnNew = new JButton(" Add ");
         btnNew.addActionListener(this);
         toolTip.setComponent(btnNew);
         btnNew.setToolTipText("Add Property Feature Information");
         btnUpd = new JButton("Update");
         btnUpd.addActionListener(this);
         toolTip.setComponent(btnUpd);
         btnUpd.setToolTipText("Update Property Feature Information");
         btnDel = new JButton("Delete");
         btnDel.addActionListener(this);
         toolTip.setComponent(btnDel);
         btnDel.setToolTipText("Delete Property Information");
         wPanel.add(btnNew);
         wPanel.add(btnUpd);
         wPanel.add(btnDel);
         midBox.add(wPanel);
         wPanel = new JPanel();
         wPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         image = new JLabel("", new      ImageIcon("c:/ATC_Application/images/skiing.jpg"), JLabel.CENTER);
         wPanel.add(image);
         botBox.add(image);
         vertBox.add(topBox);
         vertBox.add(midBox);
         vertBox.add(botBox);
         JSplitPane split = new JSplitPane();
         split.setOrientation(JSplitPane.VERTICAL_SPLIT);
         Prop_Header propHdr = new Prop_Header();
         split.setTopComponent(propHdr);
         split.setBottomComponent(vertBox);
         JScrollPane scrollPane = new JScrollPane(vertBox,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
         scrollPane.setPreferredSize(new Dimension(650,400));
         split.add(scrollPane);
         add(split);
    } // end of Property_Features constructor
    // ActionListener Interface
         public void actionPerformed(ActionEvent e){
              System.out.println("Action Listener " + e.getActionCommand());
    } // end of class
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Prop_Header extends JPanel implements ActionListener{
    private JComboBox cmbProp;
    private JTextField txtPropCode;
    private JTextField txtPropAddr1;
    private JTextField txtPropAddr2;
    private JTextField txtPropCity;
    private JTextField txtPropState;
    private JButton sel;
    private JLabel lblBlk;
    private JPanel pWork;
    private Box vertBox;     
    private Box topBox;     
    private Box midBox;     
    private Box botBox;     
    JToolTip toolTip = null;
    public Prop_Header(){
         vertBox = Box.createVerticalBox();
         topBox = Box.createHorizontalBox();
         midBox = Box.createHorizontalBox();
         botBox = Box.createHorizontalBox();
         cmbProp = new JComboBox();
         cmbProp.addItem(" ");
         cmbProp.setEditable(false);
         cmbProp.setBackground(Color.white);
         cmbProp.setPreferredSize(new Dimension(250,27));
         cmbProp.setFont(new Font("Times-Roman",Font.PLAIN,12));
         cmbProp.addActionListener(this);
         txtPropCode = new JTextField(5);
         txtPropCode.setFont(new Font("Times-Roman",Font.PLAIN,12));
         txtPropCode.setPreferredSize(new Dimension(5,27));
         txtPropCode.addActionListener(this);
         lblBlk = new JLabel(" ");
         sel = new JButton("Select");
         sel.addActionListener( this);
         toolTip = new JToolTip();
         toolTip.setComponent(cmbProp);
         cmbProp.setToolTipText("Select Property Name & Press
    Select button ");
         toolTip.setComponent(txtPropCode);
         txtPropCode.setToolTipText("Enter Property Code & Press
    Select Button ");
         toolTip.setComponent(sel);
         sel.setToolTipText("Display Property Information Based on
    Name or Code Entered ");
         pWork = new JPanel();
         pWork.setLayout(new FlowLayout(FlowLayout.CENTER));
         pWork.setBorder(BorderFactory.createTitledBorder(" Select
    Property Name or Enter Code "));
         pWork.add(new JLabel("Name: "));
         pWork.add(cmbProp);
         pWork.add(new JLabel(" Code: "));
         pWork.add(txtPropCode);
         pWork.add(lblBlk);
         pWork.add(sel);
         topBox.add(pWork);
         txtPropAddr1 = new JTextField("Address line 1",15);
         txtPropAddr1.setEditable(false);
         txtPropAddr2 = new JTextField("Address line 2",15);
         txtPropAddr2.setEditable(false);
         txtPropCity = new JTextField("City",15);
         txtPropCity.setEditable(false);
         txtPropState = new JTextField("State",3);
         txtPropState.setEditable(false);
         toolTip.setComponent(txtPropAddr1);
         txtPropAddr1.setToolTipText("First Address Line of Property");
         toolTip.setComponent(txtPropAddr2);
         txtPropAddr2.setToolTipText("Second Address Line of Property");
         toolTip.setComponent(txtPropCity);
         txtPropCity.setToolTipText("City Name of Property location");
         toolTip.setComponent(txtPropState);
         txtPropState.setToolTipText("State Code of Property location");
         midBox.add(midBox.createVerticalStrut(10));
         botBox.add(new JLabel("Address:"));
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropAddr1);
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropAddr2);
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropCity);
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropState);
         vertBox.add(topBox);
         vertBox.add(midBox);
         vertBox.add(botBox);
         add(vertBox);
    } // end of constructor
         public void actionPerformed(ActionEvent evt){
         } // end of actionPerformed
    } // end of Prop_Header

  • JTabbedPane and JScrollPane problem

    Hi all,
    I'm trying to make working JScrollPane into JTabbedPane. I have been trying several times to make it but with no acceptable effects :( I attached below the simple code to show what I'm interested in.
    PANEL1 has its dimension. I'd like to make that the JScrollPane will be active and enabled to roll when user change JFrame size to less than PANEL1 on pane1.
    Please help!
    Thanks for everyone,
    Greetings,
    import java.lang.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class Sample     {
    static JFrame fr;
    static JPanel pane1, pane2, pane3;
    static JLabel AAA, BBB, CCC;
    static JPanel PANEL1;
    static JTabbedPane panel;
    public static void main(String args[])     {
              fr = new JFrame("Sample");
              pane1 = new JPanel();
              pane1.setLayout(null);
              pane2 = new JPanel();
              pane2.setLayout(null);
              pane3 = new JPanel();
              pane3.setLayout(null);
              panel = new JTabbedPane();
              Font myfont1 = new Font("SansSerif",0,20);
              Font myfont2 = new Font("SansSerif",0,15);
              Font myfont3 = new Font("SensSerif",1,15);
              AAA = new JLabel("AAA");
              BBB = new JLabel("BBB");
              CCC = new JLabel("CCC");
              AAA.setFont(myfont2);
              BBB.setFont(myfont2);
              CCC.setFont(myfont2);
              AAA.setBounds(20,20,300,20);
              BBB.setBounds(20,50,300,20);
              CCC.setBounds(20,80,300,20);
              PANEL1 = new JPanel();
              PANEL1.setLayout(null);
              PANEL1.setBackground(java.awt.Color.CYAN);
              PANEL1.setBounds(20,15,250,300);
              PANEL1.add(AAA);
              PANEL1.add(BBB);
              PANEL1.add(CCC);
              pane1.add(PANEL1);
              panel.insertTab("A", null, pane1, null, 0);
              panel.setSelectedIndex(0);
              panel.insertTab("B", null, pane2, null, 1);
              panel.setSelectedIndex(0);
              panel.insertTab("C", null, pane3, null, 2);
              panel.setSelectedIndex(0);
              panel.setBounds(0,0,550,450);
              fr.setLayout(null);
              //fr.setResizable(false);
              fr.setBackground(java.awt.Color.CYAN);
              fr.setForeground(java.awt.Color.CYAN);
              fr.add(panel);
              fr.pack();
              fr.setSize(550, 450);
              fr.setLocationRelativeTo(null);
              fr.setVisible(true);
    }

    Unfortunately no :( Besides, I can't understand at
    all this line:
    JTabbedPane (panel)TabbedPane = ... new
    w JTabbedPane(...).add/insertTab( ... new
    JScrollPane(new JPanel(...)) ... )It's to big cut-off like for me. Can you insert it
    into my Sample?
    Regards and thanks,It's only my "dev speak". Put a ";" and a var name (, ...) whereever needed, and remove some"()".
    (Sorry, normally I don't help dev beginners on so more complex problems, with just an easy answer.)

  • JTable in JPanel

    Super(wo)man,
    Is it possible to put a JTable into a JPanel without loss
    of the column headers? Is it possible to reply with an example since you already must have tried to fix this problem.

    Hi! :)
    Yes it is possible and easy. Just put your table in a JScrollPane. Something like that:
    JTable table = new JTable (new MyTableModel ()); // assuming you already have a table model..
    JPanel panel = new JPanel (new BorderLayout ());
    panel.add (new JScrollPane (table), BorderLayout.CENTER);That's all.. :)
    CUL8er,
    Nick.

  • Resize Jpanel and JtabbedPane

    Hi All,
    i implement a resize process on jpanel that include JtabbedPane inside.
    it working fine except one thing.
    when i resize my panel it work fine, until some point it start to shrink and get smaller.
    i think it getting shrink because im getting to the end of my dialog.
    i want to avoid this beheviour and let the tabbedpanel extend as much as possible:
    this is my code:
    package test;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.GraphicsConfiguration;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.HeadlessException;
    import java.awt.Point;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.SwingUtilities;
    public class BaseMain extends JFrame {
         Point sp;
         int     jPanelStartHeight;
         int     jPanelStartWidth;
         int     jTabPaneStartHeight;
         int     jTabPaneStartWidth;
         Point offset;
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;
         private JPanel jPanel = null;
         private JTabbedPane jTabbedPane = null;
         private JPanel jPanel1 = null;
         private JTabbedPane jTabbedPane1 = null;
         private JPanel jPanel2 = null;
         private JTabbedPane jTabbedPane2 = null;
         public BaseMain() throws HeadlessException {
              // TODO Auto-generated constructor stub
              super();
              initialize();
         public BaseMain(GraphicsConfiguration arg0) {
              super(arg0);
              // TODO Auto-generated constructor stub
              initialize();
         public BaseMain(String arg0) throws HeadlessException {
              super(arg0);
              // TODO Auto-generated constructor stub
              initialize();
         public BaseMain(String arg0, GraphicsConfiguration arg1) {
              super(arg0, arg1);
              // TODO Auto-generated constructor stub
              initialize();
          * This method initializes jPanel     
          * @return javax.swing.JPanel     
         private JPanel getJPanel() {
              if (jPanel == null) {
                   GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
                   gridBagConstraints1.fill = GridBagConstraints.BOTH;
                   gridBagConstraints1.weighty = 1.0;
                   gridBagConstraints1.weightx = 1.0;
                   gridBagConstraints1.gridheight=3;
                   jPanel = new JPanel();
                   jPanel.setLayout(new BorderLayout());
                   jPanel.setBorder(BorderFactory.createLineBorder(Color.black, 2));
                   jPanel.add(getJTabbedPane(),BorderLayout.SOUTH/* gridBagConstraints1*/);
                   jPanel.addMouseListener(new java.awt.event.MouseAdapter() {
                        public void mousePressed(java.awt.event.MouseEvent e) {
                             System.out.println("mousePressed()"); // TODO Auto-generated Event stub mousePressed()
                             //original size
                             jPanelStartHeight = jPanel.getHeight();
                             jPanelStartWidth  = jPanel.getWidth();
                             jTabPaneStartHeight = jTabbedPane.getHeight();
                             jTabPaneStartWidth  = jTabbedPane.getWidth();
                              offset = SwingUtilities.convertPoint(e.getComponent(),e.getPoint(),jPanel);
                   jPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
                        public void mouseDragged(java.awt.event.MouseEvent e) {
                             System.out.println("mouseDragged()"); // TODO Auto-generated Event stub mouseDragged()
                             Point p = SwingUtilities.convertPoint(e.getComponent(),e.getPoint(), jContentPane);
                             jPanel.setSize(jPanelStartWidth,p.y+jPanelStartHeight);
                             jTabbedPane.setSize(jTabPaneStartWidth,p.y+jTabPaneStartHeight);
                             jPanel.setLocation(0/*p.x-offset.x*/,p.y-offset.y);
              return jPanel;
          * This method initializes jTabbedPane     
          * @return javax.swing.JTabbedPane     
         private JTabbedPane getJTabbedPane() {
              if (jTabbedPane == null) {
                   jTabbedPane = new JTabbedPane();
                   jTabbedPane.addTab(null, null, getJPanel1(), null);
                   jTabbedPane.addTab(null, null, getJPanel2(), null);
              return jTabbedPane;
          * This method initializes jPanel1     
          * @return javax.swing.JPanel     
         private JPanel getJPanel1() {
              if (jPanel1 == null) {
                   GridBagConstraints gridBagConstraints = new GridBagConstraints();
                   gridBagConstraints.fill = GridBagConstraints.BOTH;
                   gridBagConstraints.weighty = 1.0;
                   gridBagConstraints.weightx = 1.0;
                   jPanel1 = new JPanel();
                   jPanel1.setLayout(new GridBagLayout());
                   jPanel1.add(getJTabbedPane1(), gridBagConstraints);
              return jPanel1;
          * This method initializes jTabbedPane1     
          * @return javax.swing.JTabbedPane     
         private JTabbedPane getJTabbedPane1() {
              if (jTabbedPane1 == null) {
                   jTabbedPane1 = new JTabbedPane();
              return jTabbedPane1;
          * This method initializes jPanel2     
          * @return javax.swing.JPanel     
         private JPanel getJPanel2() {
              if (jPanel2 == null) {
                   GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
                   gridBagConstraints2.fill = GridBagConstraints.BOTH;
                   gridBagConstraints2.weighty = 1.0;
                   gridBagConstraints2.weightx = 1.0;
                   jPanel2 = new JPanel();
                   jPanel2.setLayout(new GridBagLayout());
                   jPanel2.add(getJTabbedPane2(), gridBagConstraints2);
              return jPanel2;
          * This method initializes jTabbedPane2     
          * @return javax.swing.JTabbedPane     
         private JTabbedPane getJTabbedPane2() {
              if (jTabbedPane2 == null) {
                   jTabbedPane2 = new JTabbedPane();
              return jTabbedPane2;
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        BaseMain thisClass = new BaseMain();
                        thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        thisClass.setVisible(true);
          * This method initializes this
          * @return void
         private void initialize() {
              this.setSize(300, 200);
              this.setContentPane(getJContentPane());
              this.setTitle("JFrame");
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(new BorderLayout());
                   jContentPane.add(getJPanel(), BorderLayout.SOUTH);
              return jContentPane;
    }

    hey gabi,
    i tried your code and it works just fine.... there is no shrinking or any resizing problem?! i don't know... maybe i just don't get it? so maybe u could describe your problem a little more?!
    :)

  • JTable with JPanel form as cell renderer/editor

    I have a JTable that uses a custom cell editor/renderer. The cell editor/renderer is a JPanel form with labels and text panes. As the user edits the information, I adjust the table row height (setRowHeight) and the JPanel layout manager updates the layout on the cell editor. This all seems to work fine. However, when the user exists the cell and the cell renderer is shown, it has the correct new row height but has not been correctly layed-out for the new row height. How do I force my cell renderer to be re-layout after the editor closes?

    That does not seem to work. I have done the following:
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int r, int c)
    this.table = (EditorTable) table;
    row = r;
    column = c;
    if (isSelected)
    setBackground (Preferences.selectedRowBgColor);
    else
    setBackground (formBg);
    // constructs the panel components
    setCellValue (value);
    revalidate();
    return (this);

  • JTable on JPanel on JFrame, not appearing

    I can't see the JTable that I was expecting to between the two labels, any ideas why?
    public class Workout extends JFrame {
            final String[] exercisesDoneColumnNames = {"Exercise", "# Sets", "Set 1", "Set 2", "Set 3", "Set 4", "Set 5", "Set 6", "Set 7", "Set 8", "Set 9", "Set 10"};
            private ExercisesDoneTable myModel = new ExercisesDoneTable exercisesDoneColumnNames,0);
            private JTable table = new JTable(myModel);
            public Workout() {
                super.setTitle("Workout");
                buildExerciseDoneTable();
                Toolkit tk = Toolkit.getDefaultToolkit();
                Dimension d = new Dimension();
                d = tk.getScreenSize();
                setSize((int)d.getWidth(), (int)d.getHeight());
                setLocation(0,0);
                super.setName("Workout");
                addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent evt) {   
                        System.exit(0);
                JPanel p = new JPanel();
                p.setBackground(java.awt.Color.white);
                p.add(new JLabel("left of"));
                p.add(table);
                p.add(new JLabel("right of"));
                getContentPane().add(p);
                setVisible(true);
        //helper method just splits the code to make it more readable
        private void buildExerciseDoneTable(){
            table.setPreferredScrollableViewportSize(new Dimension(500,100));
            myModel.addTableModelListener(myModel);
            table.setVisible(true);
        }

    JPanel has a default FlowLayout.
    I think you table is there, but is not displaying anything as you have specified 0 rows when creating your table model. Change that number to 1 and you will see it appear.

  • JTabbedPane and JScrollPane

    I am trying to add a JScrollPane inside a tab in a JTabbedPane.. unsuccessfully
    the JScrollPane has a JTextArea added to it...
         // tp previously declared as a JTabbedPane....
        JScrollPane jpC = new JScrollPane();
        JTextArea jtC = new JTextArea(--text source--);
        jpC.add(jtC);
        tp.addTab("Constructors",
                  null,
                  jpC,
                  "View all Constructors");on switching to the tab, it is blank.....
    the tab works fine when I simply have a simple JTextArea inside it, but it is not an option
        JTextArea jtC = new JTextArea(--text source--);
        tp.addTab("Constructors",
                  null,
                  jtC,
                  "View all Constructors");essentially what I need is to have a scrollable peice of text in all of my panes.... any idea what might be going wrong?
    I even tried declaring a new container, adding the scrollpane (with the textarea inside) to it and then creating the tab.. same result.. i understand that a tabbedpane can only contain exactly one component, so i thought this might be a work-around...
    thanks in advance,
    K

    Thanks for the quick reply.....
    actually the solution was quite illogical (IMHO!)
    all i had to do was type cast the freaking thing to (Component)!!!!!!!
        JTextArea jtC = new JTextArea(-- text source --);
        JScrollPane jpC = new JScrollPane(jtC);
        tp.addTab("Constructors",
                  null,
                  (Component)jpC,
                  "View all Constructors");again, thanks for the prompt reply!
    Kunal

  • GridBagLayout not working inside jpanel in jtabbedpane

    Have any of you experienced similar behaviour before? Any ideas what could cause this? It seems that any other layout is working except the gridbaglayout. All the components I add will be in the center of the jpanel and on top of each other no matter what gridbagconstraints I use.

    import java.awt.*;
    import javax.swing.*;
    public class GridBag_Demo extends JFrame {
        public GridBag_Demo() {
            initComponents();
        private void initComponents() {
            GridBagConstraints gridBagConstraints;
            tabbedpane = new JTabbedPane();
            panel = new JPanel();
            button1 = new JButton();
            button2 = new JButton();
            button3 = new JButton();
            label1 = new JLabel();
            label2 = new JLabel();
            label3 = new JLabel();
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setTitle("GridBag Demo");
            panel.setLayout(new GridBagLayout());
            button1.setText("button1");
            gridBagConstraints = new GridBagConstraints();
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.weighty = 1.0;
            panel.add(button1, gridBagConstraints);
            button2.setText("button2");
            gridBagConstraints.gridy = 1;
            panel.add(button2, gridBagConstraints);
            button3.setText("button3");
            gridBagConstraints.gridy = 2;
            panel.add(button3, gridBagConstraints);
            label1.setText("label1");
            gridBagConstraints.gridx = 2;
            gridBagConstraints.gridy = 0;
            panel.add(label1, gridBagConstraints);
            label2.setText("label2");
            gridBagConstraints.gridy = 1;
            panel.add(label2, gridBagConstraints);
            label3.setText("label2");
            gridBagConstraints.gridy = 2;
            panel.add(label3, gridBagConstraints);
            tabbedpane.addTab("tab1", panel);
            getContentPane().add(tabbedpane, BorderLayout.CENTER);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
        public static void main(String args[]) {
            new GridBag_Demo().setVisible(true);
        private JButton button1;
        private JButton button2;
        private JButton button3;
        private JLabel label1;
        private JLabel label2;
        private JLabel label3;
        private JPanel panel;
        private JTabbedPane tabbedpane;
    }

Maybe you are looking for

  • Since upgrading to ver 8 headers and footers on printing web pages do not print; typing response is terrible, type 20-30 char before seeing them; my PC or Firefox 8?

    If I do an end task on plugin_container using Windows task manager, the typing response problem seems to go away temporarily. However, the plugin_container process soon restarts itself and the typing issue returns. It has happened four or five times

  • Ad Hoc Estimate in cProjects

    Hello everybody, Reading the SAP help on the topic my understanding is that one can execute ECP for a cProjects before an acount assignment exists for that project. Do I understand it coorectly? If Yes, then how do I get the "AD HOC ESTIMATE" button

  • Flash error since upgrading to latest Safari

    Hi everyone, Since upgrading my browser a couple of weeks ago (Safari 6.1.2) on my Mountain Lion, I have two very infuriating problems: The first is a persisitant error message that pops up on most web pages I go to - telling me that www.facebook.com

  • Searching by file size

    Hi all, I've searched and searched for an answer to this, but didn't have any luck. I'm trying to search files by size. I've tried a smart folder, but size isn't listed as a searchable attribute. And I'm clueless when it comes to Spotlight (at least

  • How  to upload sales quotation data through LSMW?

    Hello i need to upload the sales quotation data from transaction VA21 for this we are using LSMW direct input method the program RVINVB10 is used and there are 8 segments as given below was mapped BVBAKKOM   Header records VBPAKOM      Partner record