本文整理汇总了Java中com.sun.java.swing.Painter类的典型用法代码示例。如果您正苦于以下问题:Java Painter类的具体用法?Java Painter怎么用?Java Painter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Painter类属于com.sun.java.swing包,在下文中一共展示了Painter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getType
import com.sun.java.swing.Painter; //导入依赖的package包/类
static Type getType(Object obj) {
if (obj instanceof Color) {
return Color;
} else if (obj instanceof Painter<?>) {
return Painter;
} else if (obj instanceof Insets) {
return Insets;
} else if (obj instanceof Font) {
return Font;
} else if (obj instanceof Boolean) {
return Boolean;
} else if (obj instanceof Integer) {
return Integer;
} else if (obj instanceof Icon) {
return Icon;
} else if (obj instanceof String) {
return String;
} else if (obj instanceof Dimension) {
return Dimension;
} else {
return Object;
}
}
示例2: stateChanged
import com.sun.java.swing.Painter; //导入依赖的package包/类
@Override
public void stateChanged(ChangeEvent e) {
if (tabs.getSelectedComponent() == tablePane && table == null) {
DefaultTableColumnModel columns = new DefaultTableColumnModel();
TableColumn column = new TableColumn(0, 400);
column.setHeaderValue("Key");
columns.addColumn(column);
column = new TableColumn(2, 50, new UIDefaultsRenderer(), null);
columns.addColumn(column);
column.setHeaderValue(Type.Painter.name());
table = new Table(new UITypeTableModel(painterKeys, Type.Painter, false), columns);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setRowHeight(25);
table.setPreferredScrollableViewportSize(new Dimension(500, table.getRowHeight()*10));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(this);
tablePane.getViewport().setView(table);
tablePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
}
}
示例3: updateTreeClientProperties
import com.sun.java.swing.Painter; //导入依赖的package包/类
private void updateTreeClientProperties(JTree tree) {
if (isNimbus()) {
UIDefaults map = new UIDefaults();
// Use raw types to allow compilation in 1.6 and 1.7
Painter painter = new Painter() {
@Override
public void paint(Graphics2D g, Object object, int width, int height) {}
};
map.put("Tree:TreeCell[Enabled+Selected].backgroundPainter", painter);
map.put("Tree:TreeCell[Focused+Selected].backgroundPainter", painter);
// map.put("\"Tree.cellEditor\"[Enabled+Focused].backgroundPainter", painter);
tree.putClientProperty("Nimbus.Overrides", map);
} else {
tree.putClientProperty("Nimbus.Overrides", null);
}
}
示例4: PainterChooser
import com.sun.java.swing.Painter; //导入依赖的package包/类
@SuppressWarnings("unused")
PainterChooser() {
tablePane = new JScrollPane();
renderer = new UIDefaultsRenderer();
renderer.type = Type.Painter;
editor = new JTextArea(20, 80);
editor.setText("Not Implemented");
editor.setEnabled(false);
editor.setFont(Font.decode(Font.MONOSPACED+' '+12));
JScrollPane scroller = new JScrollPane(editor);
JButton update = new JButton("Update");
update.addActionListener(this);
update.setEnabled(false);
JButton toDialog = new JButton("Switch to Dialog");
toDialog.addActionListener(this);
JPanel custom = new JPanel(null);
GroupLayout layout = new GroupLayout(custom);
custom.setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup()
.addComponent(scroller)
.addGroup(layout.createSequentialGroup()
.addComponent(update).addGap(10, 100, Short.MAX_VALUE).addComponent(toDialog)));
layout.setVerticalGroup(layout.createSequentialGroup()
.addComponent(scroller)
.addGroup(layout.createBaselineGroup(false, true)
.addComponent(update).addComponent(toDialog)));
tabs = new JTabbedPane();
pane = new JPanel(null);
layout = new GroupLayout(pane);
pane.setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup()
.addComponent(tabs)
.addComponent(renderer, Alignment.CENTER, 100, 100, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createSequentialGroup()
.addComponent(tabs).addComponent(renderer, 25, 25, 25));
tabs.add("Custom", custom);
tabs.add("Nimbus Painters", tablePane);
tabs.addChangeListener(this);
}
示例5: getPainter
import com.sun.java.swing.Painter; //导入依赖的package包/类
private Painter getPainter(TreeMap<String, Object> defaults, String key) {
Object p = defaults.get(key);
if (p instanceof UIDefaults.LazyValue) {
p = ((UIDefaults.LazyValue)p).createValue(UIManager.getDefaults());
}
return (p instanceof Painter ? (Painter)p : null);
}
示例6: MainPanel
import com.sun.java.swing.Painter; //导入依赖的package包/类
public MainPanel() {
super(new BorderLayout());
UIDefaults def = UIManager.getLookAndFeelDefaults(); //new UIDefaults();
def.put("nimbusOrange", new Color(255, 220, 35, 200));
UIDefaults d = new UIDefaults();
Painter<JComponent> painter = new Painter<JComponent>() {
@Override public void paint(Graphics2D g, JComponent c, int w, int h) {
g.setColor(new Color(100, 250, 120, 50));
g.fillRect(0, 0, w, h);
g.setColor(new Color(100, 250, 120, 150));
g.fillRect(3, h / 2, w - 6, h / 2 - 2);
}
};
d.put("ProgressBar[Enabled].foregroundPainter", painter);
d.put("ProgressBar[Enabled+Finished].foregroundPainter", painter);
BoundedRangeModel model = new DefaultBoundedRangeModel(0, 0, 0, 100);
JProgressBar progressBar1 = new JProgressBar(model);
JProgressBar progressBar2 = new JProgressBar(model);
progressBar2.putClientProperty("Nimbus.Overrides", d);
JPanel p = new JPanel();
p.setBorder(BorderFactory.createEmptyBorder(16, 16, 16, 16));
p.add(progressBar1);
p.add(progressBar2);
JButton button = new JButton("Test start");
button.addActionListener(e -> {
if (Objects.nonNull(worker) && !worker.isDone()) {
worker.cancel(true);
}
worker = new BackgroundTask();
worker.addPropertyChangeListener(new ProgressListener(progressBar1));
worker.execute();
});
Box box = Box.createHorizontalBox();
box.add(Box.createHorizontalGlue());
box.add(button);
box.add(Box.createHorizontalStrut(5));
addHierarchyListener(this);
add(p);
add(box, BorderLayout.SOUTH);
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
setPreferredSize(new Dimension(320, 240));
}
示例7: paintComponent
import com.sun.java.swing.Painter; //导入依赖的package包/类
protected void paintComponent(Graphics g) {
if (selected) {
g.setColor(UIManager.getColor("Table[Enabled+Selected].textBackground"));
g.fillRect(0, 0, getWidth(), getHeight());
} else if (row%2==0) {
g.setColor(UIManager.getColor("Table.alternateRowColor"));
g.fillRect(0, 0, getWidth(), getHeight());
}
switch (type) {
case Color: {
Color col = (Color)value;
g.setColor(col);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.fillRoundRect(2, 2, getWidth()-4, getHeight()-4, 10, 10);
} break;
case Painter: {
Painter<JComponent> painter = (Painter<JComponent>)value;
g.translate((getWidth()-getHeight())/2, 0);
painter.paint((Graphics2D)g, this, getHeight(), getHeight());
} break;
case Insets: {
Insets in = (Insets)value;
g.setColor(Color.BLACK);
g.drawRect(2, 2, getWidth()-4, getHeight()-4);
g.setColor(Color.GRAY);
g.drawRect(3+in.left, 3+in.top, getWidth()-6-in.right-in.left, getHeight()-6-in.bottom-in.top);
} break;
case Font: {
Font font = (Font)value;
drawString(g, font.getFamily(), font);
} break;
case Boolean:
drawString(g, value.toString(), BOOLEAN_FONT);
break;
case Integer: case String:
drawString(g, value.toString(), getFont());
break;
case Icon: {
Icon icn = (Icon)value;
int x = (getWidth()-icn.getIconWidth())/2;
int y = (getHeight()-icn.getIconHeight())/2;
icn.paintIcon(this, g, x, y);
} break;
case Dimension: {
Dimension d = (Dimension)value;
if (d.width < getWidth()-2 && d.height < getHeight()-2) {
g.setColor(Color.GRAY);
g.drawRect((getWidth()-d.width)/2, (getHeight()-d.height)/2, d.width, d.height);
} else {
drawString(g, d.width+" x "+d.height, getFont());
}
} break;
case Object: {
System.out.println(value.getClass());
} break;
}
}