目前我有这个JComboBox
,我怎样才能将内容集中在里面?
String[] strs = new String[]{"15158133110", "15158133124", "15158133458"};
JComboBox com = new JComboBox(strs);
Run Code Online (Sandbox Code Playgroud) 我注意到这很常见.例如,DefaultListCellRenderer,DefaultTableCellRenderer和DefaultTreeCellRenderer都使用它.我在网上看到的很多自定义单元格渲染器也使用它.我想在我的代码中使用自定义TableCellRenderer,但我对是否真的需要继承JLabel感到困惑.子类化JLabel有什么好处?
嗨,当我更新所有数据时,我有一些具有自定义渲染的单元格,deltaRowDataMode不会处理我的 cutom 单元格渲染的更改。更新行的其他单元格已正确更新。
如何给 ag 网格提供线索以正确比较此自定义单元格
每当我为JList创建自定义单元格渲染器时,我添加到它的任何元素都不会响应操作.例如,如果我让单元格渲染器返回一个带有元素的JPanel,其中一个具有ActionListener,则它根本不响应.
为什么是这样?
我目前正在尝试禁用selectable/editable /或将textInput更改为dynamic以获得我想要的结果.
我有一个带有下拉菜单和文本输入区域的自定义数据网格.但是,如果我的Model#列中没有数据,我不希望允许相应的PurchasePrice单元格中的任何条目.
col1 = new DataGridColumn("Model");
col1.headerText = "Model #";
c2.consumables_dg.addColumn(col1);
col1.width = 60;
col1.editable = false;
col1.sortable = false;
col1.cellRenderer = AlternatingRowColors_editNum_PurchasePrice;
col1 = new DataGridColumn("PurchasePrice");
col1.headerText = "Purchase Price";
c2.consumables_dg.addColumn(col1);
col1.width = 60;
col1.editable = false;
col1.sortable = false;
col1.cellRenderer = AlternatingRowColors_editNum_PurchasePrice;
Run Code Online (Sandbox Code Playgroud)
我已经尝试了AlternatingRowColors_editNum_PurchasePrice中的各种项目,但似乎没有任何工作.请看看我在if的其他声明中尝试了什么(__ enbaled)
package{
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import fl.controls.TextInput;
import flash.text.TextFieldType;
import flash.events.Event;
import fl.controls.listClasses.ListData;
import fl.controls.listClasses.ICellRenderer;
public class AlternatingRowColors_editNum_PurchasePrice extends TextInput implements ICellRenderer
{
protected var _data:Object;
protected var _listData:ListData;
protected var _selected:Boolean;
private …
Run Code Online (Sandbox Code Playgroud) 我使用的是Python 3和Gtk +3。我有一个存储在中的颜色列表Gtk.ListStore
。我希望将这些颜色显示为Gtk.ColorButton
,Gtk.CellRenderer
以便用户能够查看颜色并也可以更改颜色。我的问题是我不知道如何使用custom渲染/绘制这些按钮Gtk.CellRenderer
。
这是我的代码:
class CellRendererColorButton(Gtk.CellRenderer):
__gsignals__ = {
'color-set': (GObject.SIGNAL_RUN_FIRST, None, (str,))
}
color = GObject.property(type=str, default='rgb(0,0,255)')
def __init__(self):
super().__init__()
def do_set_property(self, pspec, value):
setattr(self, pspec.name, value)
def do_get_property(self, pspec):
return getattr(self, pspec.name)
# I have no idea about this
# def do_get_size(self, widget, cell_area):
# pass
def do_render(self, cr, widget, background_area, cell_area, flags):
# selected = (flags & Gtk.CellRendererState.SELECTED) != 0
# prelit = (flags & Gtk.CellRendererState.PRELIT) != 0
color1 …
Run Code Online (Sandbox Code Playgroud) 我在整个 React 应用程序中使用 AG-Grid,并且在某些情况下我希望 cellRenderer 在网格数据更改时进行更新。在以下两种情况下,cellRenderer 最初会正确加载,但在数据更改时不会更新:
看看这个代码和盒子
在此示例中,我使用可编辑单元重新创建了第一个用例,并使用了类组件和函数组件。将 onCellValueChanged 与 params.api.refreshCells() 一起使用,我能够更新类组件,但不能更新函数组件。
第一个问题:如何让 React 函数组件使用新的 props 重新渲染,就像在codesandbox示例中类组件重新渲染一样?
第二个问题:是否有更好的方法来更新 cellRenderer,而无需在数据更新时卸载并重新安装列中的每个单元格?
预先感谢您的帮助和指导!
...
this.state = {
columnDefs: [
{
headerName: "Editable Country",
editable: true,
field: "country",
width: 200
},
{
headerName: "Class Render",
cellRendererFramework: GridCellClass,
colId: "class-renderer",
width: 200
},
{
headerName: "Function Render",
cellRendererFramework: GridCellFunction,
colId: "function-renderer",
width: 200
}
],
rowData: []
};
}
...
<AgGridReact
rowModelType="infinite"
columnDefs={this.state.columnDefs}
enableColResize={true}
rowClassRules={{
california: function(params) {
return params.data.country === …
Run Code Online (Sandbox Code Playgroud) 我能够设置列的标题,但无法在JTable的第一列的所有行中设置图标.
public class iconRenderer extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent(JTable table,Object obj,boolean isSelected,boolean hasFocus,int row,int column){
imageicon i=(imageicon)obj;
if(obj==i)
setIcon(i.imageIcon);
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
setHorizontalAlignment(JLabel.CENTER);
return this;
}
}
public class imageicon{
ImageIcon imageIcon;
imageicon(ImageIcon icon){
imageIcon=icon;
}
}
Run Code Online (Sandbox Code Playgroud)
我的BuildTable()方法中的行和下面的行.
public void SetIcon(JTable table, int col_index, ImageIcon icon){
table.getTableHeader().getColumnModel().getColumn(col_index).setHeaderRenderer(new iconRenderer());
table.getColumnModel().getColumn(col_index).setHeaderValue(new imageicon(icon));
}
Run Code Online (Sandbox Code Playgroud)
我们如何为第一列的所有行设置它?我已尝试使用for循环,但还没有得到行迭代来设置图标.或者还有其他方法吗?
我想问在 JavaFX 中使用自定义对象制作 ListView 的最佳方法,我想要一个每个项目如下所示的列表:
我搜了一下,发现大部分人都是用细胞工厂的方法来做的。有没有其他办法?例如使用客户 fxml?
这是我的 fmxl 档案
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="557.0" prefWidth="1012.0" style="-fx-background-color: #0288D1;" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="desktop_tasker.FXMLTaskerController">
<children>
<SplitPane dividerPositions="0.5" layoutX="-8.0" layoutY="35.0" prefHeight="529.0" prefWidth="1027.0" style="-fx-background-color: #EEEEEE;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="28.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<ListView fx:id="list_todo" onEditStart="#handleButtonAction" prefHeight="527.0" prefWidth="502.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children></AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="527.0" prefWidth="640.0">
<children>
<ListView fx:id="list_done" onEditStart="#handleButtonAction" prefHeight="527.0" prefWidth="502.0" AnchorPane.bottomAnchor="0.0" …
Run Code Online (Sandbox Code Playgroud) 当我尝试使用单元格渲染来渲染自定义元素时,
这是我的组件:Action.jsx
import React from 'react';
export default (props) => (
<div>
<button
class="action-button cancel">
cancel
</button>
</div>
);
Run Code Online (Sandbox Code Playgroud)
这是我的网格选项和导入:
import AcRenderer from './Action.jsx'
...
const gridOptions = {
rowData: renderdata(),
columnDefs: [
{
headerName: "action",
cellRenderer: AcRenderer,
editable: false,
colId: "action",
filter: false,
minWidth: 220
}
],
Run Code Online (Sandbox Code Playgroud)
但我不断收到此错误:
” Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
“
有谁知道为什么?
非常感谢!
cellrenderer ×10
java ×5
swing ×4
ag-grid ×3
javascript ×2
reactjs ×2
center ×1
datagrid ×1
gtk3 ×1
gtktreeview ×1
javafx ×1
jcombobox ×1
jlabel ×1
jlist ×1
jtable ×1
listview ×1
pygobject ×1
python ×1
subclassing ×1
tablemodel ×1
updates ×1