Color « Graphics « Java Swing Q&A





1. Syntax colouring using Swing    stackoverflow.com

Is it possible to have something like a JTextArea which will color some keywords based on some mappings I have ?

2. Pick recently selected colors in java    stackoverflow.com

I would like to add a color picker dialog to my app that remembers recently selected colors, so that it's easy to pick the exact same color as before, instead of ...

3. java swing graphics color blending    stackoverflow.com

I have a bunch of shapes that I'm rendering with different graphics objects. I'd like it so when the shapes overlap, they use some alpha blending to combine the colors. However, ...

4. how to show error in result in red color in java    stackoverflow.com

I want to show error(text) in result in red color after compiling exec file and display it in textarea of gui using swing in java.

5. Problem in setting backgound color to my TreeCellRenderer    stackoverflow.com

Hi I have cretaed my own renderer. I want the back ground should be blue. I have set background color as blue also. But I donot know what is tha problem ...

6. How to change the cursor blink color?    stackoverflow.com

I don't know this is possible or not?

But i want to change the this cursor blink color...which is normally black....

i am making one java-swing based project and in that...one of ...

7. how to implement color picker in java swing    stackoverflow.com

i have used JColorChooser but look and feel is not that much great, any other way to implement color picker using java swing

8. Drawing in Java Swing with RGBA    stackoverflow.com

How can I draw in swing using RGBA (colors with transparency)? The only class I found is Color which is sRGB.

9. Override default foreground color for Flamingo's JCommandButton    stackoverflow.com

I'm using Flamingo/Substance in a Swing application and can't figure out a simple way to affect the text color for a JCommandButton. Explicitly setting the foreground color seems to have no ...





10. Color java class    stackoverflow.com

if I get color of text , I got : java.awt.Color[r=234,g=152,b=28] which should correspond to orange but when I perform the assertion : this is not working

assertEquals(Color.ORANGE.ToString(),myText.getColor());
expected :java.awt.Color[r=255,g=0,b=0] but was : java.awt.Color[r=234,g=152,b=28] any ...

11. Casting error in Java    stackoverflow.com

In my application, I am reading a .xml file and writing the data in a JTable. Apart from the data for the table, the .xml file contains an attribute defining the ...

12. Java gui colors dont load    stackoverflow.com

I've made a gui for my program and used

UIManager.put("Button.background", new Color(0,0,0));   
UIManager.put("JButton.background", new Color(0,0,0));
to make the buttons appear black. Unfortunately, this doesn't work sometimes. Without modifying the code, ...

13. NetBeans GUI Builder colors do not match previews in any Look & Feel    stackoverflow.com

I made a Java application in NetBeans with a custom JPanel. I set the background of the panel to white in multiple locations, including in the GUI Builder, in the initializing ...

14. Default changed file color on Windows Classic L&F - bad choice    forums.netbeans.org

Hi, The default colors for changed files and the ability to select them in the editor are bad. Changed files are blue and the selected line is dark blue, so you ...

15. Changing the color scheme of Java look and feel    coderanch.com

Okay I figured this one out. Here is a code sample: import javax.swing.plaf.*; import javax.swing.plaf.metal.*; public class GreenMetalTheme extends DefaultMetalTheme { public String getName() { return "Emerald"; } // greenish colors private final ColorUIResource primary1 = new ColorUIResource(51, 102, 51); private final ColorUIResource primary2 = new ColorUIResource(102, 153, 102); private final ColorUIResource primary3 = new ColorUIResource(153, 204, 153); protected ColorUIResource getPrimary1() ...

16. Color    coderanch.com

hi , i check this out import java.awt.*; class demo { public static void main(String[] args) { Color c=Color.getColor("green"); System.out.println(c.toString()); } } it returned null too. i checked the api which states. The argument is treated as the name of a system property to be obtained. The string value of this property is then interpreted as an integer which is then ...





17. component colors    coderanch.com

Hi all! According to Java 2 Certification Study Guide (RHE): If you do not explicitly set a component's foreground or background color, the component uses the foreground and background color of its immediate container. I have an applet which contains several panels (navigate using a CardLayout). Each panel contains buttons. I thought that if the buttons were not explicitly assigned a ...

18. changing cursor color    coderanch.com

19. Random Colors    coderanch.com

Hi Sumit, what u need to do is generate random values for red/gree/blue compomnents and then pass them to Color constructor. Try following code. import java.awt.*; import java.awt.event.*; class RandomColors extends Frame { TextField tf = new TextField(); Button b = new Button("Change"); int red; int green; int blue; RandomColors() { add(tf,"Center"); add(b,"South"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { ...

20. foreground color    coderanch.com

21. System Color    coderanch.com

Use the SystemColor class to use the system colors.... What type of color problems are you having? ------------------ John Zukowski Author of "Definitive Guide to Swing for Java 2" and "Java Collections" The problem is when our client test this swing application in their Solaris System, when open this application, the interface cannot display correctly with colors. We need a way ...

22. Inheriting the color of parent    coderanch.com

23. caret color    coderanch.com

24. ToolTipText color change.    coderanch.com

25. Using color in a pane    coderanch.com

26. Change color of a LookAndFeel    coderanch.com

27. Keeping a Color over a socket    coderanch.com

I have a chat server I authored from code I modified from an IBM tutorial. I have a options in a menubar that allow users to change their text color and background color, but I want the color of each individual user to be displayed on every other users display. Right now the option changes all the text to the chosen ...

28. cahnging color of Divider    coderanch.com

Hello Neeraj, it depends on what kind of LAF you use. If you use the Java LAF, then it is easy. For this LAF, you can create themes. A theme consists of 6 colors and 6 fonts. So you could write your own theme or you extend from the DefaultTheme and you can overwrite the color, which ontains the color for ...

29. Getting color    coderanch.com

30. Color picker algorithm?    coderanch.com

31. Multi-colored List    coderanch.com

Here is the code for how I used it. I was getting data from a database and based on the data, I chose the appropriate color. But I think you will be able to enfer what you need from this. public class myCellRenderer extends JLabel implements ListCellRenderer { myCellRenderer() { this.setOpaque(true); } public Component getListCellRendererComponent( JList list, Object value, int index, ...

32. How to change the TTITLE BAR color    coderanch.com

33. Choosing the right color    coderanch.com

Hello all is there anywhere i can find info on the web or book on colour schemes for my gui. I am wasting my time experimenting with colours because i can not find the right match. the GUI is going to be used on the net by users visiting to place orders so some nice colours would be good. Thank you ...

34. Motif L&F : setting color to match the one set by Color Style Manager    coderanch.com

guys, c'mon! is this question too easy to answer so its not catching anybody's attention ? Or is it too lame to have a GUI that goes with your installed color theme ? Or is swing too flexible to provide a Motif L&F without any high level support for Color schemes? some day soon, i'll move to SWT i guess... [ ...

35. changing colors in an if statement    coderanch.com

Hello I want to change the color of the shapes in my code to something more fun but it isn't working. I would like to use web safe colors such as FF3300 or something to that effect. I know I need to do sonmething like .setColor(new Color(0xFF,0x33,ox00)); etc etc but it (the color stays red when I did it to the ...

37. JComponent Color    coderanch.com

I am trying to create a custom Label component I am unable to find out 1. why this changes the default look and feel font color to black 2. though i set the color using setColor explicitly, it doesn't seem to change thank you import java.awt.*; import java.awt.font.*; import java.text.*; import javax.swing.*; public class JMultilineLabel extends JComponent { private String text; ...

38. Setting colors    coderanch.com

Hi i am having a few problems setting up colors on my text area correctly. I have set up a jtextarea and set the forground color to green. However depending on the content i want to change the text color for that paticular piece of content and not the whole jtextarea. At the moment i keep changing the color of my ...

39. Color object    coderanch.com

Hi all, Is it possible to create a color object based on the following color data. #e0e0ff The above code is defines a particular color or does the code have to consist of all integers ie. (255,143,223). I would like the user to enter the color via a similar code and to create a background color based on what they have ...

40. color changing    coderanch.com

42. Color    coderanch.com

43. Color to hexa    coderanch.com

import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class Convertor { public static void main(String[] args) { ColorConvertor convertor = new ColorConvertor(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(convertor.getButtonPanel(), "North"); f.getContentPane().add(convertor); f.getContentPane().add(convertor.getLabelPanel(), "South"); f.setSize(300,200); f.setLocation(200,200); f.setVisible(true); } } class ColorConvertor extends JPanel { JLabel rgbLabel, hexLabel; Random seed; public ColorConvertor() { seed = new Random(); } public JPanel getButtonPanel() { ...

44. Color problems    coderanch.com

The only thing that comes to mind is the possibility that you are mixing AWT and Swing components. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PaintTest { public static void main(String[] args) { final JFrame f = new JFrame(); final JFileChooser fc = new JFileChooser("."); JButton open = new JButton("open file chooser"); open.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ...

45. Hit detection by color    coderanch.com

This is for a simple point and click game. Because of the nature of the game I would prefer to use the swing UI rather than using basic graphics (it would take too long to explain why). At the moment Im using labels with gif icons and transparent backgrounds. Is there any way to find the color displayed at the point ...

46. broken color display in Java 5    coderanch.com

I've got a small app that displays a monthly calendar as a JTable, has some JComboboxes and textfields for inputting data, etc. When it runs it displays today's date in the calendar in blue background -- or rather, it should, and it used to with J2SE 1.4. Instead, now running on the Java 5 platform (with recompiled source), when it first ...

47. Unsupported Color Conversion Request    coderanch.com

48. Constructors and colours    coderanch.com

49. Setting color for non-enabled component    coderanch.com

50. Changing Swing Colours    coderanch.com

Hey all, Long time since ive been here.. heh C++. Anyway, trying to learn swing, i have a menu and a functional item listener to pick up what radio button is selected in a menu. The background is supposed to change colour depending on which radio button is selected. However, mine changes colour for a milisecond, and then back to default. ...

51. Indexed colors    coderanch.com

Hi! In the DOS-days, asm mov ax,13h; int 10h; end; would get me into graphicmode 13. Presenting me with 320x200 resolution and 256 beautiful indexed colors. The nice thing about indexed colors was how simple one could animate a picture by just rotating parts of the palette. There seems to be a IndexedColor model in Java, but how close is this ...

52. Color Problem    coderanch.com

import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class InstructorDepartments extends JPanel{ private String instructorsDepartments[] = { "iaed", "laud", "man", "econ", "hist", "ir", "pols", "ete", "me", "pe", "te", "tefl", "comd", "cs", "ee", "ie", "amer", "hart", "cci", "elit", "phil", "edeb", "hf", "mus", "mhaz", "chem", "math", "mbg", "phys", ...

53. JYearChooser() stop changing color    coderanch.com

Hi... I have in a class public class SomeDialog extends JDialog { private JYearChooser textfield = new JYearChooser(); } this shows up perfect in the dialog box but a couple of the users find it annoying that when you click in the box to enter a year instead of using arrows. The font changes to green color. Does anyone know how ...

55. Headless and java.awt.Color    coderanch.com

56. How to change group color in xp style    coderanch.com

Hi everyone somehow I have problems setting a different color for a group running the win xp style. the default color with xp style is always blue. if i change it to any other color it's still blue. the xp style seems to overwrite it. is there any way i can change the color with a hack or something or got ...

57. Question about new Color    coderanch.com

Hi all..... Maybe this isn't an awt question after all but anyway In my JPanel paintComponent i have a lot of rectangles drawn. Like g2.draw( new Rectangle( 1 , 1 , 100 , 100 ) for example. Graphics is cast to a Graphics2D object. I have a question on new Rectangle and new Color that I use alot. Does this take ...

58. Color    coderanch.com

Hi there, I have a panel that includes a label. I've added a mouse listener on the label. This is how it is working now: when I click on the label, I reset the background color of the panel: panel.setBackground(Color.PINK); and then set it to another color: panel.setBackground(new Color(30,100,10,40)); The problem is with the alpha component I am using with the ...

59. Alternate Displayed Colors    coderanch.com

I have this short code import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JTextArea; public class Main extends JFrame { public Main() { super("color Alternator"); alternate(); } /** * Creates the JTextArea with alternating colors */ public void alternate() { setDefaultCloseOperation(EXIT_ON_CLOSE); final JTextArea alternator = new JTextArea("This is where the text is displayed\n"); alternator.append("Hello World\n"); alternator.setForeground(Color.RED); alternator.append("Hello World\n"); alternator.setForeground(Color.GREEN); alternator.append("Hello World\n"); alternator.setForeground(Color.YELLOW); ...

60. How to create colors in swings....    coderanch.com

61. Colour issue (only shows grey)    coderanch.com

My program generates an 8 by 8 chessboard with alternating black and white squares. I also want to label the white squares with numbers. Here's what I have, I had it working but slightly modified it some time ago and forgot what I changed because now there aren't numbers for the last row and the squares are all grey. Any help ...

62. JComponent Color    coderanch.com

63. average of colour    coderanch.com

Hi all, I have a JWindow which serves as a note background. I am using a palette of colours for the background that range from black to white. I need to calculate the colour average so as to choose whether white of black text is to be used over the background. So if the background is black, white text will be ...

64. Is it possible to get a light-blue color?    coderanch.com

From the API page for the Color class: The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary color spaces identified by a ColorSpace. Every color has an implicit alpha value of 1.0 or an explicit one provided in the constructor. The alpha value defines the transparency of a color and can be ...

65. How to add Gradient colors to JComponents.    coderanch.com

public class GetName extends JFrame{ JButton getButton=new JButton("Get Name");//I want add gradient colors to this JButton JTextField nameField=new JTextField(); JLayeredPane pane=new JLayeredPane();//I want add gradient colors to this JPanel public GetName(){ nameField.setBounds(10,10,200,20); getButton.setBounds(15,25,100,20); setContentPane(pane); getContentPane().add(nameField,0); getContentPane().add(getButton,0); getButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); } public static void main(String args[]){ GetName t=new GetName(); t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); t.show(); } }

67. Unsupported color conversion request    coderanch.com

68. awt colors    coderanch.com

69. Problem changing colours    coderanch.com

Hi guys I currently have a small problem with drawing different colours to my JPanel. I currently have buttons that changes the value of an int (colourStatus) when pressed. it also calls a method to change the colour, based upon the status selected. private void whiteButtonActionPerformed(java.awt.event.ActionEvent evt) { colourStatus = 1; changeColour(); } private void changeColour(){ switch (colourStatus) { case 1 ...

70. Colour bounds method    coderanch.com

Hi! Was wondering if there is a comparable method in the Java API (maybe in Swing) that carries out the same function as this one found in ActionScript. It's a method which determines a rectangular region that fully encloses all pixels of a specified color within a bitmap image; so if there are two red circles at opposite corners of an ...

71. GUI Color Changer    coderanch.com

So the program is supposed to change the fill color of a predetermined shape from slider or text field values. The problem is that my sliders aren't updating from text field values. I've seen several examples of how to specify the event using KeyListner on the web, but my teacher specified that we should be using ActionListner. I'd appreciate any help. ...

72. Suggestions on colour convertor program    coderanch.com

Hi, I want to write a program that maps the colours of a user-selected image to the closest matching colours in a given set. Here is the basic operation: -User opens an image using the program -The program checks the colour of each pixel in the image -For each pixel, the program chooses the closest matching colour from a set of ...

73. Creating an IndexColorModel with 8 Colours    coderanch.com

Hi, I have updated the above mentioned thread. The documentation gives these parameter descriptions: public IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasalpha) bits - the number of bits each pixel occupies size - the size of the color component arrays cmap - the array of color components start - the starting offset of the first color component hasalpha ...

74. can we change the default selection color of setSelection() in jface    coderanch.com

I wanna to highlight a specific node of a tree viewer while clicking on one button. For this I'm using the setSelection method of jface's tree viewer. It works but with default highlighting color. Is there any option to change the background or foreground color of specific node in jface tree viewer. I'm using the following code to highlight a specific ...

75. Changing the progress color based on value    coderanch.com

Hi all i have a table where in one coloumn i have to fill the value example 50% and the cell background color should be green till the 50% of the Cell i think you got what i want. so i thought of putting the JProgress bar in the renderrer of the table cell, but problem is how to change the ...

76. Changing colors on my swing app    coderanch.com

I would like to change colors on my Swing app; I do not need to change anything else about the look and feel. I want to do this while the application is running. I have found a method that, when put in a class that extends one of the basic look and feel classes, does some of what I want. It ...

77. negative color    coderanch.com

Hi all, I'm trying to define a simple method that takes an image and returns its negative. It appears I have some trouble with the method that returns the negative of the pixel color (only black becomes white, but every other color is returned as yellow). Here's the code: private GImage makeColorNegative(GImage image) { int[][]array = image.getPixelArray(); for(int row = 0; ...

78. Help with switch color    java-forums.org

79. How to Change the color of MultiColumnListBox    java-forums.org

Hello Experts, I am facing one problem.I want after the code fetches data from DB(MS-SQL),it will changes the color of the row in a particular condition. public MultiColumnListBox ListCRVM = new MultiColumnListBox(); public Data dataListCRVM = new Data(); ListCRVM.setName( "ListCRVM" ); ListCRVM.clear(); add( ListCRVM ); ListCRVM.setVisible( true ); ListCRVM.setEnabled( true ); ListCRVM.setRequestFocusEnabled( true ); ListCRVM.setTabOrder( 0 ); ListCRVM.setRowSource( dataListCRVM ); ListCRVM.setColumnCount( ...

80. Color Change of data    java-forums.org

Hello Experts, My requirement is if priority is highest priority then data appears in red color otherwise in black color.I wrote folowing query for this. SELECT * FROM CRVMReq where [Priority] like 'Highest Priority' AND ReqStatus like 'OPEN' and ReqStatusPool like 'FOCUS' if([CRVMReq].[Priority]='Highest Priority') { ListCRVM.setForeground( Color.red ); } else { ListCRVM.setForeground( Color.black ); } } I don't know how to ...

81. Change color of a region    java-forums.org

I have this program, that draws a JPanel with 25*15 red rectangles. Now, when I click in one rectangle, I want to change the color of the rectangle to green (if it was red) and then to red again (if the user clicks again). So far I already calculate the coordinates of the clicked rectangle but I don't know how to ...

83. how can i change color of disabled jcombox    java-forums.org

The combo is made up of a textfield (or label) and a button. You need to find out how to access the textfield inside the combo. Have you tried accessing the components inside the combo box? Changing the editor or renderer? I refuse to believe it is not possible to do without Look and Feel.

84. Color scale    java-forums.org

86. color coding a graphical outline of a body using a gui    forums.oracle.com

Hi all, I'm new to Java and I am developing a GUI which shows the outline of a human body and parts of the body change color. a user enters values and depending on whether the values are above or below the threshold set that part of the body would turn red or green. The problem i'm encountering at the moment ...