本文整理汇总了Java中javax.swing.table.JTableHeader类的典型用法代码示例。如果您正苦于以下问题:Java JTableHeader类的具体用法?Java JTableHeader怎么用?Java JTableHeader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JTableHeader类属于javax.swing.table包,在下文中一共展示了JTableHeader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseClicked
import javax.swing.table.JTableHeader; //导入依赖的package包/类
public void mouseClicked(MouseEvent e) {
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column);
if (!e.isControlDown()) {
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
status = status + (e.isShiftDown() ? -1
: 1);
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
setSortingStatus(column, status);
}
}
示例2: FitTableColumns
import javax.swing.table.JTableHeader; //导入依赖的package包/类
public static void FitTableColumns(JTable myTable){
JTableHeader header = myTable.getTableHeader();
int rowCount = myTable.getRowCount();
Enumeration columns = myTable.getColumnModel().getColumns();
while(columns.hasMoreElements()){
TableColumn column = (TableColumn)columns.nextElement();
int col = header.getColumnModel().getColumnIndex(column.getIdentifier());
int width = (int)myTable.getTableHeader().getDefaultRenderer()
.getTableCellRendererComponent(myTable, column.getIdentifier()
, false, false, -1, col).getPreferredSize().getWidth();
for(int row = 0; row<rowCount; row++){
int preferedWidth = (int)myTable.getCellRenderer(row, col).getTableCellRendererComponent(myTable,
myTable.getValueAt(row, col), false, false, row, col).getPreferredSize().getWidth();
width = Math.max(width, preferedWidth);
}
header.setResizingColumn(column); // ���к���Ҫ
column.setWidth(width+myTable.getIntercellSpacing().width);
}
}
示例3: getDesignValue
import javax.swing.table.JTableHeader; //导入依赖的package包/类
@Override
public Object getDesignValue() {
Object value = null;
try {
value = property.getTargetValue();
if (value instanceof JTableHeader) {
JTableHeader header = (JTableHeader)value;
header.setResizingAllowed(resizingAllowed);
header.setReorderingAllowed(reorderingAllowed);
}
} catch (IllegalAccessException iaex) {
Logger.getLogger(getClass().getName()).log(Level.INFO, iaex.getMessage(), iaex);
} catch (InvocationTargetException itex) {
Logger.getLogger(getClass().getName()).log(Level.INFO, itex.getMessage(), itex);
}
return value;
}
示例4: configureEnclosingScrollPane
import javax.swing.table.JTableHeader; //导入依赖的package包/类
/** Overridden - JTable's implementation of the method will
* actually attach (and leave behind) a gratuitous border
* on the enclosing scroll pane. */
@Override
protected final void configureEnclosingScrollPane() {
Container p = getParent();
if (p instanceof JViewport) {
Container gp = p.getParent();
if (gp instanceof JScrollPane) {
JScrollPane scrollPane = (JScrollPane) gp;
JViewport viewport = scrollPane.getViewport();
if ((viewport == null) || (viewport.getView() != this)) {
return;
}
JTableHeader jth = getTableHeader();
if (jth != null) {
jth.setBorder(null);
}
scrollPane.setColumnHeaderView(jth);
}
}
}
示例5: mouseClicked
import javax.swing.table.JTableHeader; //导入依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column);
if (!e.isControlDown()) {
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
status += e.isShiftDown() ? -1 : 1;
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
setSortingStatus(column, status);
if(issueTable != null) {
issueTable.sortOrderChanged();
}
}
}
示例6: setTableHeader
import javax.swing.table.JTableHeader; //导入依赖的package包/类
public void setTableHeader(JTableHeader tableHeader) {
if (this.tableHeader != null) {
this.tableHeader.removeMouseListener(mouseListener);
TableCellRenderer defaultRenderer =
this.tableHeader.getDefaultRenderer();
if (defaultRenderer instanceof SortableHeaderRenderer) {
this.tableHeader.setDefaultRenderer(
((SortableHeaderRenderer) defaultRenderer)
.tableCellRenderer);
}
}
this.tableHeader = tableHeader;
if (this.tableHeader != null) {
this.tableHeader.addMouseListener(mouseListener);
this.tableHeader.setDefaultRenderer(
new SortableHeaderRenderer(
this.tableHeader.getDefaultRenderer()));
}
}
示例7: addMouseListenerToHeaderInTable
import javax.swing.table.JTableHeader; //导入依赖的package包/类
public void addMouseListenerToHeaderInTable(JTable table) {
final TableSorter sorter = this;
final JTable tableView = table;
tableView.setColumnSelectionAllowed(false);
MouseAdapter listMouseListener = new MouseAdapter() {
boolean ascending = false;
public void mouseClicked(MouseEvent e) {
TableColumnModel columnModel = tableView.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = tableView.convertColumnIndexToModel(viewColumn);
if (e.getClickCount() == 1 && column != -1) {
//System.out.println("Sorting ...");
//int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK;
//boolean ascending = (shiftPressed == 0);
if (column == sortBy)
ascending = !ascending;
else
ascending = true;
sorter.sortByColumn(column, ascending);
tableView.getTableHeader().updateUI();
}
}
};
JTableHeader th = tableView.getTableHeader();
th.addMouseListener(listMouseListener);
}
示例8: setTableHeader
import javax.swing.table.JTableHeader; //导入依赖的package包/类
public void setTableHeader(JTableHeader tableHeader)
{
if( this.tableHeader != null )
{
this.tableHeader.removeMouseListener(mouseListener);
TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
if( defaultRenderer instanceof SortableHeaderRenderer )
{
this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
}
}
this.tableHeader = tableHeader;
if( this.tableHeader != null )
{
this.tableHeader.addMouseListener(mouseListener);
this.tableHeader.setDefaultRenderer(new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
}
}
示例9: sizeColumnsToFit2
import javax.swing.table.JTableHeader; //导入依赖的package包/类
public static void sizeColumnsToFit2(JTable table, int columnMargin,DataNode line){
JTableHeader tableHeader = table.getTableHeader();
FontMetrics lineFontMetrics = table.getFontMetrics(table.getFont());
FontMetrics headerFontMetrics = tableHeader.getFontMetrics(tableHeader.getFont());
//System.out.println(line+" MaxColumnLength: "+line.getMaxColumnLength());
for (int t=0; t<table.getRowCount();t++){
for (int tt=0; tt<table.getColumnCount();tt++){
table.getColumnModel().getColumn(tt).setPreferredWidth(
(columnMargin*2)+line.getMaxColumnLength().get(table.getColumnName(tt))*lineFontMetrics.charsWidth("ABCD1834".toCharArray(),0,8)/8
);
tableHeader.getColumnModel().getColumn(tt).setPreferredWidth(
(columnMargin*2)+line.getMaxColumnLength().get(table.getColumnName(tt))*headerFontMetrics.charsWidth("ABCDabcd1834".toCharArray(),0,12)/12
);
//System.out.println("Zeile "+t+" Spalte "+tt+" "+" getPreferredWidth"+table.getColumnModel().getColumn(tt).getPreferredWidth()+" line.getMaxColumnLength"+line.getMaxColumnLength().get(table.getColumnName(t)));
}
}
}
示例10: getTableCellRendererComponent
import javax.swing.table.JTableHeader; //导入依赖的package包/类
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
boolean timelineColumn = column == table.convertColumnIndexToModel(col);
setVisible(timelineColumn);
Component c = impl.getTableCellRendererComponent(table, timelineColumn ?
" " : value, isSelected, hasFocus, row, col); // NOI18N
if (timelineColumn) {
if (getParent() == null && c instanceof Container) ((Container)c).add(this);
JTableHeader header = table.getTableHeader();
if (painter == null) initStaticUI(c, header);
TableColumn _column = header.getColumnModel().getColumn(col);
setSize(_column.getWidth(), header.getSize().height);
}
return c;
}
示例11: initStaticUI
import javax.swing.table.JTableHeader; //导入依赖的package包/类
private static void initStaticUI(Component c, JTableHeader header) {
painter = new LabelRenderer(true);
Color color = c.getForeground();
if (color == null) color = header.getForeground();
if (color == null) color = UIManager.getColor("TableHeader.foreground"); // NOI18N
if (color != null) painter.setForeground(color);
Font font = c.getFont();
if (font == null) font = header.getFont();
if (font == null) font = UIManager.getFont("TableHeader.font"); // NOI18N
if (font != null) painter.setFont(font);
if (UIUtils.isWindowsXPLookAndFeel()) Y_LAF_OFFSET = 1;
else if (UIUtils.isNimbusLookAndFeel()) Y_LAF_OFFSET = -1;
else Y_LAF_OFFSET = 0;
}
示例12: getTableCellRendererComponent
import javax.swing.table.JTableHeader; //导入依赖的package包/类
public Component getTableCellRendererComponent (JTable table, Object value,
boolean isSelected, boolean hasFocus,int row, int column) {
if (table != null) {
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
}
}
AttlistTableModel tm = (AttlistTableModel)table.getModel();
if (column == tm.SortedColumn)
setIcon(tm.ascending ? new javax.swing.ImageIcon(getClass().getResource("down.gif")): // NOI18N
new javax.swing.ImageIcon(getClass().getResource("up.gif"))); // NOI18N
else setIcon(new javax.swing.ImageIcon(getClass().getResource("no.gif"))); // NOI18N
setText((value == null) ? "" : value.toString()); // NOI18N
return this;
}
示例13: subSetEnabled
import javax.swing.table.JTableHeader; //导入依赖的package包/类
/**
* Enables/disables all subcomponents of this panel. This also toggles the ability to drag and
* drop and conditionally freezes the ability to resize the file list column headers.
*
* @param enabled
* Whether or not this panel is enabled
*/
private void subSetEnabled(final boolean enabled) {
if (!SwingUtilities.isEventDispatchThread()) {
String errMsg = "subSetEnabled is not on the EDT but it should be";
IllegalStateException ex = new IllegalStateException(errMsg);
LOG.log(Level.SEVERE, errMsg, ex);
throw ex;
}
enableDragAndDrop(enabled);
GUIHelper.enableComponent(this, enabled);
setEnabled(true); // Re-enable the panel since GUIHelper.enableComponent disables it
sslButton.setEnabled(enabled && profileModel.getProfileAdapter() != null
&& profileModel.getProfileAdapter().getSSLCertChain() != null);
browseDirectoryButton
.setEnabled(enabled && getSelectedProfile().getType() == ProfileType.FILESYSTEM);
JTableHeader header = fileList.getTableHeader();
if (header != null) {
header.setResizingAllowed(enabled);
}
}
示例14: addMouseListenerToHeaderInTable
import javax.swing.table.JTableHeader; //导入依赖的package包/类
public void addMouseListenerToHeaderInTable(JTable table) {
final TableSorter sorter = this;
final JTable tableView = table;
tableView.setColumnSelectionAllowed(false);
MouseAdapter listMouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
TableColumnModel columnModel = tableView.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = tableView.convertColumnIndexToModel(viewColumn);
if (e.getClickCount() == 1 && column != -1) {
System.out.println("Sorting ...");
int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
boolean ascending = (shiftPressed == 0);
sorter.sortByColumn(column, ascending);
}
}
};
JTableHeader th = tableView.getTableHeader();
th.addMouseListener(listMouseListener);
}
示例15: mouseClicked
import javax.swing.table.JTableHeader; //导入依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
if (!e.isPopupTrigger()) {
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
if (columnModel.getColumn(viewColumn).getHeaderValue().equals("File Name")) {
FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_NAME, false);
FileTable.this.fileList.updateTableData();
} else if (columnModel.getColumn(viewColumn).getHeaderValue().equals("Type")) {
FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_TYPE, false);
FileTable.this.fileList.updateTableData();
} else if (columnModel.getColumn(viewColumn).getHeaderValue().equals("Last Modified")) {
FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_MODIFIED, false);
FileTable.this.fileList.updateTableData();
} else if (columnModel.getColumn(viewColumn).getHeaderValue().equals("Size")) {
FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_SIZE, false);
FileTable.this.fileList.updateTableData();
}
}
}
}