Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Thumbs up JTable using swings

    Here bellow my code is working fine but JTable click on maximize button alternate colors of the rows was 'not alternate' and scrolling up and down was same probleam...

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Testdemo
            extends     JFrame
    {
        private     JTabbedPane tabbedPane;
        private     JPanel      panel1;
        private     JPanel      panel2;
        private     JPanel      panel3;
    JTable mappingTable;
    JScrollPane pane;
    
        public Testdemo()
        {
            // NOTE: to reduce the amount of code in this example, it uses
            // panels with a NULL layout.  This is NOT suitable for
            // production code since it may not display correctly for
            // a look-and-feel.
            
            setTitle( "Tabbed Pane Application" );
            setSize( 300, 200 );
            setBackground( Color.gray );
    
            JPanel topPanel = new JPanel();
            topPanel.setLayout( new BorderLayout() );
            getContentPane().add( topPanel );
    
            // Create the tab pages
            createPage1();
            createPage2();
            createPage3();
    
            // Create a tabbed pane
            tabbedPane = new JTabbedPane();
            tabbedPane.addTab( "Page 1", panel1 );
            tabbedPane.addTab( "Page 2", panel2 );
            tabbedPane.addTab( "Page 3", panel3 );
            topPanel.add( tabbedPane, BorderLayout.CENTER );
        }
    
        public void createPage1()
        {
            panel1 = new JPanel();
            panel1.setLayout( new BorderLayout() );
    
            Object values[] = { "SNo","Source system", "Source Table","Source field Name","Data Type","Field Length","NaturalIdentifier","Target System","Target Table","Field Name","Data Type","Length","Primary Key","Field Description","Data Mapping Rule","Transformation Rules","ETL Load rules(one per table)","Comment","Status" };
             TableModel model = new DefaultTableModel(values, 1010){
                    public boolean isCellEditable(int row,int column)
                        {
                        
                        if(column==0||column==5||column==11)
                        return false;
                        return true;
                        }
                    };
                 mappingTable = new javax.swing.JTable (1010,19) {
                         public Component prepareRenderer(TableCellRenderer renderer, int row, int column){
                                Component returnComp = super.prepareRenderer(renderer, row, column);
                                Color alternateColor = new Color(252,242,206);
                                Color whiteColor = Color.WHITE;
                                if (!returnComp.getBackground().equals(getSelectionBackground())){
                                    Color bg = (row % 2 == 0 ? alternateColor : whiteColor);
                                    returnComp .setBackground(bg);
                                    bg = null;
                                }
                                return returnComp;
                         }
                    
                        public boolean isCellEditable(int row,int column)
                        {
                            for(int i=0;i<mappingTable.getRowCount();i++)
                            {
                                for(int j=0;j<mappingTable.getColumnCount();j++)
                                {
                                    if(mappingTable.getValueAt(i,j)!=null&&mappingTable.getValueAt(i,j).toString().length()>=1)
                                    {
                                        for(int k=0;k<=i;k++)
                                        {
                                            mappingTable.setValueAt((k+1), k, 0);
                                            
                                        }
                                    }
                                }
                            }
                            if(column==0)
                                return false;
                                return true;
                        }
                        
                          
                        };
                       mappingTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
                       pane = new JScrollPane(mappingTable);
                      
                       JLabel l=new JLabel("KKKKK");
                       panel1.add(pane,BorderLayout.CENTER);
        }
    
        public void createPage2()
        {
            panel2 = new JPanel();
            panel2.setLayout( new BorderLayout() );
    
            panel2.add( new JButton( "North" ), BorderLayout.NORTH );
            panel2.add( new JButton( "South" ), BorderLayout.SOUTH );
            panel2.add( new JButton( "East" ), BorderLayout.EAST );
            panel2.add( new JButton( "West" ), BorderLayout.WEST );
            panel2.add( new JButton( "Center" ), BorderLayout.CENTER );
        }
    
        public void createPage3()
        {
            panel3 = new JPanel();
            panel3.setLayout( new GridLayout( 3, 2 ) );
    
            panel3.add( new JLabel( "Field 1:" ) );
            panel3.add( new TextArea() );
            panel3.add( new JLabel( "Field 2:" ) );
            panel3.add( new TextArea() );
            panel3.add( new JLabel( "Field 3:" ) );
            panel3.add( new TextArea() );
        }
    
        // Main method to get things started
        public static void main( String args[] )
        {
            // Create an instance of the test application
            Testdemo mainFrame  = new Testdemo();
            mainFrame.setVisible( true );
        }
    }
    Last edited by Fubarable; 12-28-2010 at 01:39 PM. Reason: moderator edit: code tags added

  2. #2
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    I don't understand your question?
    This code does work fine. What's the exact problem?

    -regards

Similar Threads

  1. JAVA-Swings
    By HariPrasad in forum AWT / Swing
    Replies: 6
    Last Post: 12-29-2010, 02:29 AM
  2. How to get the GUI Help for Swings?
    By CHARU_SH in forum Eclipse
    Replies: 1
    Last Post: 05-19-2010, 11:03 AM
  3. Swings
    By bsantosh in forum AWT / Swing
    Replies: 4
    Last Post: 08-31-2009, 02:10 PM
  4. interface in swings
    By r.srimathi in forum AWT / Swing
    Replies: 4
    Last Post: 01-29-2009, 08:44 AM
  5. awt and swings
    By masa in forum AWT / Swing
    Replies: 2
    Last Post: 11-24-2008, 07:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •