Tag: colors

Java:使用颜色操作(加,减)? – 恒定类中的颜色

我正在使用java.awt.Color实例。 有没有办法对颜色进行算术运算? 像rgb(20, 20, 20) + rgb(10, 200, 170) = rgb(30, 220, 190) ? 我正在尝试做的事情:我有一个带有桌子的gui,如果用户点击一个单元格,其他单元格会根据它们与所选单元格的关系改变颜色。 我正在寻找一种方法来避免硬编码基色是什么,以及它们改变的颜色值。 因此,所选单元格可能是rgb(255, 0, 0) ,其他所有内容可能基于它们的值在rgb(0, 0, 0)和rgb(0, 255, 0) 。 我在想…枚举? import java.awt.Color; public enum ColorConstant { SELECTED (new rgb(255, 0, 0), “Red”), MAX_DISTANCE (new rgb(0, 255, 0), “Green”) private Color shade; private ??? whichColorToModify; }

BufferedImage颜色饱和度

我正在使用jfreesane和Apache PDFBox编写一个简单的扫描应用程序。 这是扫描码: InetAddress address = InetAddress.getByName(“192.168.0.17”); SaneSession session = SaneSession.withRemoteSane(address); List devices = session.listDevices(); SaneDevice device = devices.get(0); device.open(); device.getOption(“resolution”).setIntegerValue(300); BufferedImage bimg = device.acquireImage(); File file = new File(“test_scan.png”); ImageIO.write(bimg, “png”, file); device.close(); 并制作PDF: PDDocument document = new PDDocument(); float width = bimg.getWidth(); float height = bimg.getHeight(); PDPage page = new PDPage(new PDRectangle(width, height)); […]

如何更改JSeparator的颜色?

问题出在标题中。 我目前正在做类似的事情: jSperator = new JSeparator(); jSeparator1.setForeground(new java.awt.Color(255, 51, 51)); 但分隔符保持默认颜色,如212,212,212。

如何设置字符串的颜色

有谁知道如何设置将使用System.out打印的字符串的颜色? 这是我目前的代码: System.out.println(“TEXT THAT NEEDS TO BE A DIFFERENT COLOR.”);

从用户获取颜色作为字符串并在接受枚举值的方法中使用它?

如何从用户获取颜色作为String并在接受Color enum值的方法中使用它? 想法是获取用户选择的颜色并将值传递(或以任何其他方式处理情境)到方法element.setBackground(java.awt.Color) 。

JTable细胞颜色

有人能举例说明如何在JTable中获取特定单元格的背景颜色吗? 我无法找到如何执行此操作的示例。 获取单元格中的值的大量示例,而不是单元格的背景颜色。

如何更改JOptionPane中的按钮背景

我想知道是否有人知道是否可以更改JOptionPane内按钮的背景颜色。 我知道如何使用UIManager更改整个JOptionPane背景,但知道我想要的是在JOptionPane设置单独的okButton,cancelButton等来分隔各个颜色。 如果我能做到这一点,我该怎么做? 谢谢您的帮助。

更改单元格颜色而不更改其他单元格中的颜色(Jtable)

所以说我们有一个31列10行的JTable。 我想将2列4行的颜色更改为红色。 在我这样做之后,改变另一种细胞颜色而不会失去我之前细胞的颜色。 我试过以下但没有成功: public class CellR extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setForeground(Color.white); if(row == TestHotel.v.getRow() && column == TestHotel.v.getCol()){ // Only for specific cell // c.setFont(/* special font*/); // you may want to address isSelected here too setForeground(Color.BLACK); setBackground(Color.RED); } return […]

清晰的图形部分与底层图像

我正在制作各种各样的“游戏”,玩家必须点击在屏幕上弹跳的图像。 问题是屏幕处于黑暗中,鼠标光标是一个“闪光灯”,它“点亮”它周围的一个小圆圈。 我在一个类中有一个JFrame ,包括: public class GameFrame { public static void main(String[] args) throws IOException { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); JFrame jf = new JFrame(“Flashlight Game”); jf.setVisible(true); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(d); jf.setLocationRelativeTo(null); GamePanel gp = new GamePanel(); jf.add(gp); } } 我有另一个extends JPanel类。 以下是与我的问题相关的字段: private Point mouse; //location set by a MouseMotionListener private BufferedImage myImage; private int imageX; […]

JProgressbar:如何根据进度改变颜色?

是否可以根据进度的值更改条形颜色? 我尝试了以下但它不起作用: percentUsed = (int)(((float) used / (float) max) * BAR_PERCENTAGE); if (percentUsed >= ORANGE_THRESHOLD && percentUsed = RED_THRESHOLD) { if (!m_redIndicator) { LOG.warn(String.format(“Memory usage exceeds %d percent.”, RED_THRESHOLD)); m_orangeIndicator = true; m_redIndicator = true; } colour = Color.RED; } else { m_orangeIndicator = false; m_redIndicator = false; colour = Color.GREEN; } m_memUsageBar.setForeground(colour); m_memUsageBar.setValue(percentUsed); m_memUsageBar.updateUI(); […]