From 350785ff491baca1aae325c5b4636cc998e2951e Mon Sep 17 00:00:00 2001 From: hche10x Date: Wed, 18 Oct 2006 05:57:36 +0000 Subject: [PATCH] 1. Fix EDKT411: Need right and left scroll bar to display find results 2. Add a function in Tools.java to adjust a table's all columns' width git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1788 6f19259b-4bc3-4df7-8a09-765794883524 --- .../frameworkwizard/common/Tools.java | 17 ++++++++++++++ .../common/find/FindResult.java | 23 +++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java index e5cce71045..90c38fd8fe 100644 --- a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java +++ b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java @@ -27,6 +27,7 @@ import javax.swing.DefaultListModel; import javax.swing.JComboBox; import javax.swing.JList; import javax.swing.JOptionPane; +import javax.swing.JTable; import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea; import org.tianocore.MsaHeaderDocument.MsaHeader; @@ -552,6 +553,22 @@ public class Tools { resizeComponentWidth(c, containerWidth, preferredWidth); resizeComponentHeight(c, containerHeight, preferredHeight); } + + /** + To adjust each column's width to meet the table's size + + @param t the table need to be adjusted + @param width the new width of the table + + **/ + public static void resizeTableColumn(JTable t, int width) { + if (t != null) { + int columnCount = t.getColumnCount(); + for (int index = 0; index < columnCount; index++) { + t.getColumn(t.getColumnName(index)).setPreferredWidth(width / columnCount); + } + } + } /** * To relocate the input component diff --git a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/find/FindResult.java b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/find/FindResult.java index 0033797bb9..5dcc7aa944 100644 --- a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/find/FindResult.java +++ b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/find/FindResult.java @@ -17,6 +17,7 @@ package org.tianocore.frameworkwizard.common.find; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; import java.awt.event.WindowEvent; import java.util.Vector; @@ -37,7 +38,7 @@ import org.tianocore.frameworkwizard.common.Log; import org.tianocore.frameworkwizard.common.Tools; import org.tianocore.frameworkwizard.common.ui.IFrame; -public class FindResult extends IFrame implements TableModelListener { +public class FindResult extends IFrame implements TableModelListener, ComponentListener { /// /// Define class Serial Version UID @@ -156,6 +157,10 @@ public class FindResult extends IFrame implements TableModelListener { if (jTable == null) { model = new IDefaultTableModel(); jTable = new JTable(model); + jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); + jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + jTable.getModel().addTableModelListener(this); model.addColumn("Name"); model.addColumn("Type"); @@ -168,9 +173,18 @@ public class FindResult extends IFrame implements TableModelListener { jTable.getColumn("Produced by").setCellRenderer(new MyTableCellRenderer()); jTable.getColumn("Consumed by").setCellRenderer(new MyTableCellRenderer()); jTable.getColumn("Declared by").setCellRenderer(new MyTableCellRenderer()); - - jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - jTable.getModel().addTableModelListener(this); + +// jTable.getColumn("Name").setPreferredWidth((this.getSize().width - 30) / 5); +// jTable.getColumn("Type").setPreferredWidth((this.getSize().width - 30) / 5); +// jTable.getColumn("Produced by").setPreferredWidth((this.getSize().width - 30) / 5); +// jTable.getColumn("Consumed by").setPreferredWidth((this.getSize().width - 30) / 5); +// jTable.getColumn("Declared by").setPreferredWidth((this.getSize().width - 30) / 5); + int columnWidth = (this.getSize().width - 28) / 5; + jTable.getColumn("Name").setPreferredWidth(columnWidth); + jTable.getColumn("Type").setPreferredWidth(columnWidth); + jTable.getColumn("Produced by").setPreferredWidth(columnWidth); + jTable.getColumn("Consumed by").setPreferredWidth(columnWidth); + jTable.getColumn("Declared by").setPreferredWidth(columnWidth); } return jTable; } @@ -451,6 +465,7 @@ public class FindResult extends IFrame implements TableModelListener { intPreferredHeight); Tools.centerComponent(this.jButtonClose, intCurrentWidth, intCurrentHeight, intPreferredHeight, DataType.SPACE_TO_BOTTOM_FOR_CLOSE_BUTTON); + Tools.resizeTableColumn(this.jTable, this.getSize().width - 28); } /* (non-Javadoc) -- 2.39.2