Browse Source

REPORT-127437 fix: 修复 jtable 滚动条问题

newui
lemon 4 months ago
parent
commit
b13d045bdd
  1. 16
      designer-base/src/main/java/com/fr/design/actions/help/alphafine/component/CustomSortPane.java
  2. 2
      designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java
  3. 7
      designer-base/src/main/java/com/fr/design/gui/itableeditorpane/ParameterTableModel.java
  4. 55
      designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java
  5. 1
      designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITReplaceMainDialog.java
  6. 30
      designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableEditor.java
  7. 36
      designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableEditorPane.java

16
designer-base/src/main/java/com/fr/design/actions/help/alphafine/component/CustomSortPane.java

@ -74,14 +74,14 @@ public class CustomSortPane extends JPanel {
}
private void createToolbarPane() {
top = new UIButton(new LazyIcon("top"));
bottom = new UIButton(new LazyIcon("bottom"));
up = new UIButton(new LazyIcon("up"));
down = new UIButton(new LazyIcon("down"));
top.setDisabledIcon(new LazyIcon("top_disable"));
bottom.setDisabledIcon(new LazyIcon("bottom_disable"));
up.setDisabledIcon(new LazyIcon("up_disable"));
down.setDisabledIcon(new LazyIcon("down_disable"));
top = new UIButton(new LazyIcon("to_top"));
bottom = new UIButton(new LazyIcon("to_bottom"));
up = new UIButton(new LazyIcon("move_up"));
down = new UIButton(new LazyIcon("move_down"));
top.setDisabledIcon(new LazyIcon("to_top").disabled());
bottom.setDisabledIcon(new LazyIcon("to_bottom").disabled());
up.setDisabledIcon(new LazyIcon("move_up").disabled());
down.setDisabledIcon(new LazyIcon("move_down").disabled());
top.addActionListener(e -> {
SwingUtilities.invokeLater(() -> {
sortItemPane.setComponentZOrder(selectedLabel, 0);

2
designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java

@ -261,7 +261,7 @@ public class UICheckListPopup extends UIPopupMenu {
} else if (selectCount < checkBoxList.size() - 1) {
//虽然有选中,但是要判断此时全选状态去换图标
if (checkBoxList.get(0).isSelected()) {
checkBox.setSelectedIcon(new LazyIcon("checkbox_part_checked"));
checkBox.setSelectedIcon(new LazyIcon("checkbox_checked"));
} else {
checkBox.setIcon(new LazyIcon("checkbox_part_checked"));
}

7
designer-base/src/main/java/com/fr/design/gui/itableeditorpane/ParameterTableModel.java

@ -1,5 +1,7 @@
package com.fr.design.gui.itableeditorpane;
import com.fine.theme.utils.FineUIStyle;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.fr.base.Parameter;
import com.fr.design.editor.ValueEditorPane;
import com.fr.design.editor.ValueEditorPaneFactory;
@ -240,8 +242,11 @@ public class ParameterTableModel extends UITableModelAdapter<ParameterProvider>
public ParameterValueRenderer(ValueEditorPane valueEditorPane) {
disableLable = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Paramete_Name"));
disableLable.setForeground(Color.pink);
FineUIStyle.setStyle(disableLable, FineUIStyle.LABEL_WARNING_TIP);
disableLable.setHorizontalAlignment(SwingConstants.LEFT);
disableLable.setOpaque(true);
disableLable.setBackground(FlatUIUtils.getUIColor("background.normal", Color.WHITE));
disableLable.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("defaultBorderColor")));
editor = valueEditorPane;
}

55
designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java

@ -16,6 +16,7 @@ import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
@ -29,6 +30,10 @@ import java.awt.GridLayout;
import java.awt.Insets;
import java.util.List;
import static com.fine.swing.ui.layout.Layouts.cell;
import static com.fine.swing.ui.layout.Layouts.column;
import static com.fine.swing.ui.layout.Layouts.row;
/**
* 表格编辑面板,一般是两列.- 用泛型实现用的时候请定义T.model里面的T要一样
*
@ -40,9 +45,9 @@ public class UITableEditorPane<T> extends BasicPane {
*
*/
private static final long serialVersionUID = 6855793816972735815L;
private JTable editTable;
protected static JTable editTable;
// 放置action 的按钮.
private UITableModelAdapter<T> tableModel;
protected UITableModelAdapter<T> tableModel;
private String leftLabelName;
private JPanel buttonPane;
@ -77,20 +82,37 @@ public class UITableEditorPane<T> extends BasicPane {
UIScrollPane scrollPane = new UIScrollPane(editTable);
scrollPane.setBorder(new FineRoundBorder());
pane.add(scrollPane, BorderLayout.CENTER);
initbuttonPane(action);
JPanel controlPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
controlPane.add(buttonPane, BorderLayout.EAST);
controlPane.add(content == null ? l : content, BorderLayout.WEST);
pane.add(controlPane, BorderLayout.NORTH);
pane.add(column(cell(controlPane), cell(buildScrollTablePane(scrollPane)).weight(1)).getComponent());
this.editTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer());
this.editTable.setDefaultRenderer(Object.class, new TableRenderer());
this.editTable.setRowHeight(FineUIScale.scale(24));
}
/**
* 组合 jtable 和垂直滚动条
* @param scrollPane
* @return
*/
protected Component buildScrollTablePane(JScrollPane scrollPane) {
return row(
cell(scrollPane).weight(1),
column(
cell(new UILabel()).with(it -> {
it.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 1, UIManager.getColor("defaultBorderColor")));
it.setPreferredSize(FineUIScale.scale(new Dimension(scrollPane.getVerticalScrollBar().getWidth(), (int) editTable.getTableHeader().getPreferredSize().getHeight())));
}),
cell(scrollPane.getVerticalScrollBar()).weight(1).with(it -> {
it.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 1, UIManager.getColor("defaultBorderColor")));
}))
).getComponent();
}
public UITableModelAdapter<T> getTableModel() {
return tableModel;
}
@ -175,7 +197,10 @@ public class UITableEditorPane<T> extends BasicPane {
return buttonPane;
}
public JTable getEditTable() {
/**
* @return jTable
*/
public static JTable getEditTable() {
return editTable;
}
@ -210,7 +235,11 @@ public class UITableEditorPane<T> extends BasicPane {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
((JComponent) component).setBorder(UIManager.getBorder("TableHeader.cellBorder"));
if (column == table.getColumnCount() - 1) {
((JComponent) component).setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("defaultBorderColor")));
} else {
((JComponent) component).setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")));
}
return component;
}
}
@ -231,9 +260,15 @@ public class UITableEditorPane<T> extends BasicPane {
((JLabel) component).setToolTipText(toolTipText);
}
}
((JComponent) component).setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")),
new ScaledEmptyBorder(0,4,0,0)));
if (column == table.getColumnCount() - 1) {
((JComponent) component).setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("defaultBorderColor")),
new ScaledEmptyBorder(0,4,0,0)));
} else {
((JComponent) component).setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")),
new ScaledEmptyBorder(0,4,0,0)));
}
component.setBackground(FlatUIUtils.getUIColor("background.normal", Color.WHITE));
return component;
}

1
designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITReplaceMainDialog.java

@ -39,7 +39,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import static com.fr.design.actions.replace.ui.ITTableEditorPane.editTable;
import static com.fr.design.actions.replace.ui.ITTableEditorPane.getEditTable;
/**

30
designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableEditor.java

@ -1,13 +1,13 @@
package com.fr.design.actions.replace.ui;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.fine.theme.utils.FineUIScale;
import com.fr.design.actions.replace.info.Info;
import com.fr.design.actions.replace.info.base.ITContent;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itableeditorpane.UITableEditAction;
import com.fr.design.gui.itableeditorpane.UITableEditorPane;
import com.fr.design.gui.itableeditorpane.UITableModelAdapter;
import com.fr.design.i18n.Toolkit;
@ -17,12 +17,10 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.plaf.UIResource;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.Color;
import java.awt.Component;
@ -62,26 +60,14 @@ public class ITTableEditor extends UITableModelAdapter {
});
DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
((JComponent) c).setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")),
new ScaledEmptyBorder(0,4,0,0)));
c.setBackground(FlatUIUtils.getUIColor("background.normal", Color.WHITE));
return c;
}
};
this.setDefaultRenderer(UILabel.class, cellRenderer);
this.setDefaultRenderer(UILabel.class, new UITableEditorPane.TableRenderer());
this.setDefaultEditor(ITTableButton.class, new ITTableButton());
this.setDefaultRenderer(ITTableButton.class, new ITTableButton());
this.setDefaultEditor(Boolean.class, new ITBooleanEditor());
this.setDefaultRenderer(Boolean.class, new ITBooleanRenderer());
this.createTable().getColumnModel().getColumn(ITReplaceSouthPanel.CONTENT_INDEX).setMaxWidth(50);
this.createTable().getColumnModel().getColumn(ITReplaceSouthPanel.CHECKBOX_INDEX).setMaxWidth(28);
this.createTable().getColumnModel().getColumn(ITReplaceSouthPanel.CONTENT_INDEX).setMaxWidth(FineUIScale.scale(50));
this.createTable().getColumnModel().getColumn(ITReplaceSouthPanel.CHECKBOX_INDEX).setMaxWidth(FineUIScale.scale(28));
this.createTable().getColumnModel().getColumn(ITReplaceSouthPanel.CHECKBOX_INDEX).setCellRenderer(new ITBooleanRenderer());
}
@ -283,7 +269,11 @@ public class ITTableEditor extends UITableModelAdapter {
setEnabled(!content.isReplaced());
setSelected((value != null && ((Boolean) value).booleanValue()));
setUI(getUICheckBoxUI());
setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")));
if (column == table.getColumnCount() - 1) {
setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("defaultBorderColor")));
} else {
setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")));
}
setBackground(Color.WHITE);
return this;
}

36
designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableEditorPane.java

@ -4,15 +4,12 @@ import com.fine.theme.icon.LazyIcon;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.fr.base.TRL;
import com.fr.design.actions.replace.info.base.ITContent;
import com.fr.design.border.UIRoundedBorder;
import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.BasicPane;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itableeditorpane.UITableEditAction;
import com.fr.design.gui.itableeditorpane.UITableEditorPane;
import com.fr.design.gui.itableeditorpane.UITableModelAdapter;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
@ -21,6 +18,7 @@ import com.fr.general.GeneralUtils;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
@ -38,23 +36,23 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import static com.fine.swing.ui.layout.Layouts.cell;
/**
* 表格面板
*
* @author Destiny.Lin
* @version 11.0
* created by Destiny.Lin on 2022-08-22
* @since
* Created On
*/
public class ITTableEditorPane<T> extends BasicPane {
public static JTable editTable;
private UITableModelAdapter<T> tableModel;
public class ITTableEditorPane<T> extends UITableEditorPane<T> {
private String leftLabelName;
private JPanel buttonPane;
public ITTableEditorPane(UITableModelAdapter<T> model) {
this.tableModel = model;
this.initComponent(model.createAction());
super(model);
}
@ -64,7 +62,7 @@ public class ITTableEditorPane<T> extends BasicPane {
*
* @param action
*/
private void initComponent(UITableEditAction[] action) {
public void initComponent(UITableEditAction[] action) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
editTable = tableModel.createTable();
editTable.addMouseListener(new MouseClickListener() {
@ -91,8 +89,8 @@ public class ITTableEditorPane<T> extends BasicPane {
}
});
UIScrollPane scrollPane = new UIScrollPane(editTable);
scrollPane.setBorder(new UIRoundedBorder(UIConstants.TITLED_BORDER_COLOR, 1, UIConstants.ARC));
this.add(scrollPane, BorderLayout.CENTER);
add(cell(buildScrollTablePane(scrollPane)).weight(1).getComponent());
}
/**
@ -223,7 +221,11 @@ public class ITTableEditorPane<T> extends BasicPane {
component.setForeground(tableHeader.getForeground());
component.setBackground(tableHeader.getBackground());
component.setFont(tableHeader.getFont());
component.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
if (column == table.getColumnCount() - 1) {
component.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("defaultBorderColor")));
} else {
component.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")));
}
return component;
}
@ -237,13 +239,7 @@ public class ITTableEditorPane<T> extends BasicPane {
* @param table
*/
public static void makeFace(JTable table) {
Dimension size = table.getTableHeader().getPreferredSize();
size.height = 26;//设置新的表头高度
table.getTableHeader().setBackground(FlatUIUtils.getUIColor("TableHeader.background", Color.WHITE));
table.getTableHeader().setPreferredSize(size);
table.getTableHeader().setDefaultRenderer(new ITHeaderRenderer(table));
}

Loading…
Cancel
Save