Results 1 to 3 of 3
  1. #1
    poddy88 is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default Colour Specific Cell within Table

    Created a basic table, fields have been filled but i want to colour in a specific cell how would i do this? what will i also need to import

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    Vector<String> rowOne = new Vector<String>();
    rowOne.addElement("R1-C1");
    rowOne.addElement("R1-C2");
    rowOne.addElement("R1-C3");
    rowOne.addElement("R1-C4");

    Vector<String> rowTwo = new Vector<String>();
    rowTwo.addElement("R2-C1");
    rowTwo.addElement("R2-C2");
    rowTwo.addElement("R2-C3");
    rowTwo.addElement("R2-C4");

    Vector<String> rowThree = new Vector<String>();
    rowThree.addElement("R3-C1");
    rowThree.addElement("R3-C2");
    rowThree.addElement("R3-C3");
    rowThree.addElement("R3-C4");

    Vector<String> rowFour = new Vector<String>();
    rowFour.addElement("R4-C1");
    rowFour.addElement("R4-C2");
    rowFour.addElement("R4-C3");
    rowFour.addElement("R4-C4");

    Vector<Vector> rowData = new Vector<Vector>();
    rowData.addElement(rowOne);
    rowData.addElement(rowTwo);
    rowData.addElement(rowThree);
    rowData.addElement(rowFour);

    Vector<String> columnNames = new Vector<String>();
    columnNames.addElement("Column One");
    columnNames.addElement("Column Two");
    columnNames.addElement("Column Three");
    columnNames.addElement("Column Four");
    JTable table = new JTable(rowData, columnNames);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Import java.awt.Component class into your application first. Then on the component object call the setBackground() with the correct argument. You have to import awt.Color class as well.

  3. #3
    poddy88 is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default

    Could you give an example please, im not that great at this

Similar Threads

  1. Replies: 2
    Last Post: 02-28-2009, 07:30 AM
  2. manual BMP rendering colour issues
    By Goseph in forum AWT / Swing
    Replies: 0
    Last Post: 02-24-2009, 08:26 PM
  3. Replies: 2
    Last Post: 11-08-2008, 10:40 AM
  4. figuring out the current colour of my appelet
    By vortexprogramming in forum New To Java
    Replies: 2
    Last Post: 07-15-2008, 04:16 AM
  5. Select specific cell
    By Echilon in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 07:47 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
  •