jtable将指定的单元格取消边框?

发布网友 发布时间:2022-04-25 13:55

我来回答

1个回答

热心网友 时间:2023-10-27 11:45

所谓单元格取消边框,实则是水平线和垂直线都去除了,

/*
 * @(#)TableDemo.java1.23 05/11/30
 *  
 * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
 *  
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *  
 * -Redistribution of source code must retain the above copyright notice, this
 *  list of conditions and the following disclaimer.
 *  
 * -Redistribution in binary form must reproce the above copyright notice,  
 *  this list of conditions and the following disclaimer in the documentation
 *  and/or other materials provided with the distribution.
 *  
 * Neither the name of Sun Microsystems, Inc. or the names of contributors may  
 * be used to endorse or promote procts derived from this software without  
 * specific prior written permission.
 *  
 * This software is provided "AS IS," without a warranty of any kind. ALL  
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST  
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,  
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY  
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,  
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *  
 * You acknowledge that this software is not designed, licensed or intended
 * for use in the design, construction, operation or maintenance of any
 * nuclear facility.
 */
 
/*
 * @(#)TableDemo.java1.23 05/11/30
 */
 
 
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import javax.swing.border.*;
import javax.swing.colorchooser.*;
import javax.swing.filechooser.*;
import javax.accessibility.*;
 
import java.awt.*;
import java.awt.event.*;
import java.awt.print.PrinterException;
import java.beans.*;
import java.util.*;
import java.io.*;
import java.applet.*;
import java.net.*;
 
import java.text.MessageFormat;
 
/**
 * Table demo
 *
 * @version 1.23 11/30/05
 * @author Philip Milne
 * @author Steve Wilson
 */
public class TableDemo extends DemoMole {
    JTable      tableView;
    JScrollPane scrollpane;
    Dimension   origin = new Dimension(0, 0);
     
    JCheckBox   isColumnReorderingAllowedCheckBox;
    JCheckBox   showHorizontalLinesCheckBox;
    JCheckBox   showVerticalLinesCheckBox;
 
    JCheckBox   isColumnSelectionAllowedCheckBox;
    JCheckBox   isRowSelectionAllowedCheckBox;
 
    JLabel      interCellSpacingLabel;
    JLabel      rowHeightLabel;
 
    JSlider     interCellSpacingSlider;
    JSlider     rowHeightSlider;
 
    JComboBoxselectionModeComboBox = null;
    JComboBoxresizeModeComboBox = null;
 
    JLabel      headerLabel;
    JLabel      footerLabel;
 
    JTextField  headerTextField;
    JTextField  footerTextField;
 
    JCheckBox   fitWidth;
    JButton     printButton;
 
    JPanel      controlPanel;
    JScrollPane tableAggregate;
 
    String path = "ImageClub/food/";
 
    final int INITIAL_ROWHEIGHT = 33;
 
    /**
     * main method allows us to run as a standalone demo.
     */
    public static void main(String[] args) {
TableDemo demo = new TableDemo(null);
demo.mainImpl();
    }
 
    /**
     * TableDemo Constructor
     */
    public TableDemo(SwingSet2 swingset) {
super(swingset, "TableDemo", "toolbar/JTable.gif");

getDemoPanel().setLayout(new BorderLayout());
controlPanel = new JPanel();
        controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.X_AXIS));
JPanel cbPanel = new JPanel(new GridLayout(3, 2));
        JPanel labelPanel = new JPanel(new GridLayout(2, 1)) {
            public Dimension getMaximumSize() {
                return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
            }
        };
        JPanel sliderPanel = new JPanel(new GridLayout(2, 1)) {
            public Dimension getMaximumSize() {
                return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
            }
        };
JPanel comboPanel = new JPanel(new GridLayout(2, 1));
        JPanel printPanel = new JPanel(new ColumnLayout());
 
getDemoPanel().add(controlPanel, BorderLayout.NORTH);
Vector relatedComponents = new Vector();
 
 
        // check box panel
    isColumnReorderingAllowedCheckBox = new JCheckBox(getString("TableDemo.reordering_allowed"), true);
        isColumnReorderingAllowedCheckBox.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
       boolean flag = ((JCheckBox)e.getSource()).isSelected();
                tableView.getTableHeader().setReorderingAllowed(flag);
                tableView.repaint();
   }
        });
 
    showHorizontalLinesCheckBox = new JCheckBox(getString("TableDemo.horz_lines"), true);
        showHorizontalLinesCheckBox.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
       boolean flag = ((JCheckBox)e.getSource()).isSelected();
                tableView.setShowHorizontalLines(flag); ;
                tableView.repaint();
   }
        });
 
    showVerticalLinesCheckBox = new JCheckBox(getString("TableDemo.vert_lines"), true);
        showVerticalLinesCheckBox.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
       boolean flag = ((JCheckBox)e.getSource()).isSelected();
                tableView.setShowVerticalLines(flag); ;
                tableView.repaint();
   }
        });
 
// Show that showHorizontal/Vertical controls are related
relatedComponents.removeAllElements();
relatedComponents.add(showHorizontalLinesCheckBox);
relatedComponents.add(showVerticalLinesCheckBox);
buildAccessibleGroup(relatedComponents);
 
        isRowSelectionAllowedCheckBox = new JCheckBox(getString("TableDemo.row_selection"), true);
        isRowSelectionAllowedCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                boolean flag = ((JCheckBox)e.getSource()).isSelected();
                tableView.setRowSelectionAllowed(flag); ;
                tableView.repaint();
            }
        });
 
        isColumnSelectionAllowedCheckBox = new JCheckBox(getString("TableDemo.column_selection"), false);
        isColumnSelectionAllowedCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                boolean flag = ((JCheckBox)e.getSource()).isSelected();
                tableView.setColumnSelectionAllowed(flag); ;
                tableView.repaint();
            }


声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com