Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:10:50+00:00 2026-05-27T10:10:50+00:00

My question concerns removing the borders of column headers in JTable. My class extends

  • 0

My question concerns removing the borders of column headers in JTable.

My class extends JTable and hence i managed to erase all the other borders by doing:

super.setShowHorizontalLines(false);
super.setShowVerticalLines(false);

But this doesn’t erase the borders in the column header. How to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:10:51+00:00Added an answer on May 27, 2026 at 10:10 am

    you have to extract JLabel from TableHeader and set there Border, for example there are changed Borders only for 1st. Column

    enter image description here

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.Border;
    import javax.swing.table.*;
    
    public class LabelHeaderSample {
    
        public static void main(String args[]) {
            Icon redIcon = new DiamondIcon(Color.red);
            Icon blueIcon = new DiamondIcon(Color.blue);
            Object rows[][] = {{"one", "ichi - \u4E00", new DiamondIcon(Color.red)},
                {"two", "ni - \u4E8C", new DiamondIcon(Color.red)},
                {"three", "san - \u4E09", new DiamondIcon(Color.red)},
                {"four", "shi - \u56DB", new DiamondIcon(Color.red)},
                {"five", "go - \u4E94", new DiamondIcon(Color.red)},
                {"six", "roku - \u516D", new DiamondIcon(Color.red)},
                {"seven", "shichi - \u4E03", new DiamondIcon(Color.red)},
                {"eight", "hachi - \u516B", new DiamondIcon(Color.red)},
                {"nine", "kyu - \u4E5D", new DiamondIcon(Color.red)},
                {"ten", "ju - \u5341", new DiamondIcon(Color.red)}};
            JFrame frame = new JFrame("Label Header");
            String headers[] = {"English", "Japanese", "Icon"};
            JTable table = new JTable(rows, headers);
            JScrollPane scrollPane = new JScrollPane(table);
            Border headerBorder = UIManager.getBorder("TableHeader.cellBorder");
            JLabel blueLabel = new JLabel(headers[0], blueIcon, JLabel.CENTER);
    
            blueLabel.setBorder(null);// < - - - here you set Borders
    
            JLabel redLabel = new JLabel(headers[1], redIcon, JLabel.CENTER);
            redLabel.setBorder(headerBorder);
            TableCellRenderer renderer = new JComponentTableCellRenderer();
            TableColumnModel columnModel = table.getColumnModel();
            TableColumn column0 = columnModel.getColumn(0);
            TableColumn column1 = columnModel.getColumn(1);
            TableColumn column2 = columnModel.getColumn(2);
            column0.setHeaderRenderer(renderer);
            column0.setHeaderValue(blueLabel);
            column1.setHeaderRenderer(renderer);
            column1.setHeaderValue(redLabel);
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);
        }
    
        private LabelHeaderSample() {
        }
    }
    
    class DiamondIcon implements Icon {
    
        private Color color;
        private boolean selected;
        private int width;
        private int height;
        private Polygon poly;
        private static final int DEFAULT_WIDTH = 10;
        private static final int DEFAULT_HEIGHT = 10;
    
        public DiamondIcon(Color color) {
            this(color, true, DEFAULT_WIDTH, DEFAULT_HEIGHT);
        }
    
        public DiamondIcon(Color color, boolean selected) {
            this(color, selected, DEFAULT_WIDTH, DEFAULT_HEIGHT);
        }
    
        public DiamondIcon(Color color, boolean selected, int width, int height) {
            this.color = color;
            this.selected = selected;
            this.width = width;
            this.height = height;
            initPolygon();
        }
    
        private void initPolygon() {
            poly = new Polygon();
            int halfWidth = width / 2;
            int halfHeight = height / 2;
            poly.addPoint(0, halfHeight);
            poly.addPoint(halfWidth, 0);
            poly.addPoint(width, halfHeight);
            poly.addPoint(halfWidth, height);
        }
    
        public int getIconHeight() {
            return height;
        }
    
        public int getIconWidth() {
            return width;
        }
    
        public void paintIcon(Component c, Graphics g, int x, int y) {
            g.setColor(color);
            g.translate(x, y);
            if (selected) {
                g.fillPolygon(poly);
            } else {
                g.drawPolygon(poly);
            }
            g.translate(-x, -y);
        }
    }
    
    class JComponentTableCellRenderer implements TableCellRenderer {
    
        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int row, int column) {
            return (JComponent) value;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question concerns the replaceAll method of String class. My purpose is to replace
My question concerns c# and how to access Static members ... Well I don't
My question concerns Google Web Toolkit (GWT). I'm about to begin development for a
My question concerns markup that surrounds some of the default phone number labels in
In fact, my question concerns an algorithm. I need to be able to attach
Question Alright, I'm confused by all the buzzwords and press release bingo going on.
My question concerns the output of this statement: for x in range(4), y in
This question concerns running python files in terminal that are not stored in the
I am using Sqlite3 with Flask microframework, but this question concerns only the Sqlite
My question concerns the android development. I would like to know if the method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.