Java set color colors

Java set color colors

Defines a contract between user-interface components and an assistive technology that provides access to those components.

Provides a set of «lightweight» (all-Java language) components that, to the maximum degree possible, work the same on all platforms.

Provides one interface and many abstract classes that Swing uses to provide its pluggable look-and-feel capabilities.

Provides user interface objects built according to the Java look and feel (once codenamed Metal), which is the default look and feel.

Uses of Color in java.awt

Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.

Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.

Sets the paint mode of this graphics context to alternate between this graphics context’s current color and the new specified color.

Constructs a RadialGradientPaint with a default NO_CYCLE repeating method and SRGB color space, using the center as the focus point.

Читайте также:  Php curl post json example

Constructs a RadialGradientPaint with a default SRGB color space, using the center as the focus point.

Constructs a RadialGradientPaint with a default NO_CYCLE repeating method and SRGB color space, using the center as the focus point.

Constructs a RadialGradientPaint with a default SRGB color space, using the center as the focus point.

Uses of Color in javax.accessibility

Uses of Color in javax.swing

Creates a beveled border of the specified type, using the specified colors for the inner and outer highlight and shadow areas.

Creates a beveled border of the specified type with softened corners, using the specified highlighting and shadowing.

Creates a beveled border of the specified type with softened corners, using the specified colors for the inner and outer edges of the highlight and the shadow areas.

Sets the background color at index to background which can be null , in which case the tab’s background color will default to the background color of the tabbedpane .

Sets the foreground color at index to foreground which can be null , in which case the tab’s foreground color will default to the foreground color of this tabbedpane .

Sets the color used to draw the background of selected items, which cell renderers can use fill selected cells.

Sets the color used to draw the foreground of selected items, which cell renderers can use to render text and graphics.

Uses of Color in javax.swing.border

Fields in javax.swing.border declared as Color
Modifier and Type Field and Description
protected Color MatteBorder. color
protected Color EtchedBorder. highlight
protected Color BevelBorder. highlightInner
protected Color BevelBorder. highlightOuter
protected Color LineBorder. lineColor
protected Color EtchedBorder. shadow
protected Color BevelBorder. shadowInner
protected Color BevelBorder. shadowOuter
protected Color TitledBorder. titleColor
Methods in javax.swing.border that return Color
Modifier and Type Method and Description
Color EtchedBorder. getHighlightColor ()

Creates a TitledBorder instance with the specified border, title, title-justification, title-position, title-font, and title-color.

Uses of Color in javax.swing.colorchooser

Methods in javax.swing.colorchooser that return Color
Modifier and Type Method and Description
protected Color AbstractColorChooserPanel. getColorFromModel ()

Creates a DefaultColorSelectionModel with the current color set to color , which should be non- null .

Uses of Color in javax.swing.plaf

Uses of Color in javax.swing.plaf.basic

Fields in javax.swing.plaf.basic declared as Color
Modifier and Type Field and Description
protected Color BasicMenuItemUI. acceleratorForeground
protected Color BasicMenuItemUI. acceleratorSelectionForeground
protected Color BasicBorders.ButtonBorder. darkShadow
protected Color BasicBorders.FieldBorder. darkShadow
protected Color BasicTabbedPaneUI. darkShadow
protected Color BasicMenuItemUI. disabledForeground
protected Color BasicToolBarUI. dockingBorderColor
protected Color BasicToolBarUI. dockingColor
protected Color BasicToolBarUI. floatingBorderColor
protected Color BasicToolBarUI. floatingColor
protected Color BasicTabbedPaneUI. focus
protected Color BasicBorders.ButtonBorder. highlight
protected Color BasicBorders.FieldBorder. highlight
protected Color BasicBorders.SplitPaneBorder. highlight
protected Color BasicTabbedPaneUI. highlight
protected Color BasicSeparatorUI. highlight
protected Color BasicBorders.ButtonBorder. lightHighlight
protected Color BasicBorders.FieldBorder. lightHighlight
protected Color BasicTabbedPaneUI. lightHighlight
protected Color BasicInternalFrameTitlePane. notSelectedTextColor
protected Color BasicInternalFrameTitlePane. notSelectedTitleColor
protected Color BasicInternalFrameTitlePane. selectedTextColor
protected Color BasicInternalFrameTitlePane. selectedTitleColor
protected Color BasicMenuItemUI. selectionBackground
protected Color BasicMenuItemUI. selectionForeground
protected Color BasicBorders.ButtonBorder. shadow
protected Color BasicBorders.FieldBorder. shadow
protected Color BasicBorders.SplitPaneBorder. shadow
protected Color BasicTabbedPaneUI. shadow
protected Color BasicSeparatorUI. shadow
protected Color BasicScrollBarUI. thumbColor
protected Color BasicScrollBarUI. thumbDarkShadowColor
protected Color BasicScrollBarUI. thumbHighlightColor
protected Color BasicScrollBarUI. thumbLightShadowColor
protected Color BasicScrollBarUI. trackColor
protected Color BasicScrollBarUI. trackHighlightColor
Methods in javax.swing.plaf.basic that return Color
Modifier and Type Method and Description
Color BasicToolBarUI.DragWindow. getBorderColor ()
Color BasicToolBarUI. getDockingColor ()

The «selectionBackground» is the color of the text when it is painted over an unfilled area of the progress bar.

The «selectionForeground» is the color of the text when it is painted over a filled area of the progress bar.

Creates a BasicArrowButton whose arrow is drawn in the specified direction and with the specified colors.

Uses of Color in javax.swing.plaf.metal

Uses of Color in javax.swing.plaf.nimbus

Methods in javax.swing.plaf.nimbus that return Color
Modifier and Type Method and Description
protected Color AbstractRegionPainter. decodeColor (Color color1, Color color2, float midPoint)

Get a derived color, derived colors are shared instances and is color value will change when its parent UIDefault color changes.

Given parameters for creating a LinearGradientPaint, this method will create and return a linear gradient paint.

Given parameters for creating a RadialGradientPaint, this method will create and return a radial gradient paint.

Uses of Color in javax.swing.plaf.synth

Uses of Color in javax.swing.table

Methods in javax.swing.table that return Color
Modifier and Type Method and Description
Color JTableHeader.AccessibleJTableHeader.AccessibleJTableHeaderEntry. getBackground ()
Color JTableHeader.AccessibleJTableHeader.AccessibleJTableHeaderEntry. getForeground ()
Methods in javax.swing.table with parameters of type Color
Modifier and Type Method and Description
void DefaultTableCellRenderer. setBackground (Color c)

Uses of Color in javax.swing.text

Uses of Color in javax.swing.text.html

Uses of Color in javax.swing.tree

Fields in javax.swing.tree declared as Color
Modifier and Type Field and Description
protected Color DefaultTreeCellRenderer. backgroundNonSelectionColor

Источник

Set Color in Java

Set Color in Java

Graphics is the pictorial representation of graphs, images, shapes that helps statistics to understand better. Java programming allows users to draw the Graphics instance as per the need. Graphics is an abstract class that has various abstract functions for drawing components over the desired devices.

Below is the code block to show how graphics work.

import javax.swing.*; import java.applet.Applet; import java.awt.*;  public class ColorsAndFrames   public static void main(String[] args)   ShowGraphics graphics = new ShowGraphics();  JFrame frame = new JFrame();  frame.setVisible(true);  frame.setSize(400, 400);  frame.add(graphics);  >   static class ShowGraphics extends Applet   public void paint(Graphics g)   g.setColor(Color.GREEN);  g.drawOval(30, 130, 50, 60);  Color myColor = new Color(255, 200, 113);  g.setColor(myColor);  g.fillRect(40, 60, 30, 60);  >  > > 

In the above code block, the public class holds the driver code and a static class to draw shapes. The ShowGraphics class is a user-defined class that extends the Applet class. The Applet does not run on its own but as a supporting program in other applications. It is generally defined to use along with web pages and in HTML code.

It has a method paint that comes from the java.awt.Component object. The method paints applets and takes a Graphics instance as a parameter. The object holds basic information to draw images like circles, rectangles, ovals and make manipulations over the axis. The Graphics instance gets used to invoke various functions.

On the other hand, the setColor function sets the graphic context color to the desired color. It can be a custom user-defined color or can be from the Color class. Custom colors can get defined by giving RGB values in the constructor of the Color class. The parameters are in order of Red, Green, and Blue, and the values range from 0-255. The drawOval() function is a method that draws the oval shapes. It takes four parameters x,y, width, and height.

The driver code that is the main class created the instance of the Applet extended class. The JFrame class is instantiated to hold Java Swing components that initially are invisible. So, the window is explicitly allowed to be visible using the setVisible method. The method takes a Boolean parameter and does not return any value.

Once the window starts appearing, its size is defined using the setSize function. The given parameters take the values in pixels. An instance of the ShowGraphics class is passed to the add function. The method will append the specified graph into the container. It throws NullPointerException when the component passes are null.

Other than the Java program, the Applet class can get directly called from the HTML code, and the container in the browser renders the information from the Applet class.

Below is the attached Applet image that is formed as an output when you execute the program above:

Applet viewer frame holding two shapes

Rashmi is a professional Software Developer with hands on over varied tech stack. She has been working on Java, Springboot, Microservices, Typescript, MySQL, Graphql and more. She loves to spread knowledge via her writings. She is keen taking up new things and adopt in her career.

Related Article — Java Color

Источник

Java set color colors

Color can be controlled by accessing the Color class. The Color class yields the class constants shown in the table below. The expression Color.red gives the Color constant for red.

g.setColor (Color.blue);
g.drawString(«Love this Java!», 120, 120);
g.setColor (Color.orange);
g.drawLine(50, 50, 150, 50);

You can fine tune your colors by controlling the RGB (red/green/blue) density values. Each of these 3 colors has 256 shades. It is possible to «mix» a new shade of color by selecting an integer from 0 to 255 and passing it to a Color constructor. The value 0 indicates the absence of a color in the mixture, and the value 255 indicates the maximum saturation of that color. The color black has RGB(0,0,0) and the color white has RGB(255,255,255).
There are 256 * 256 *256 = 2 24 possible colors in this scheme. WOW!

To create your own color:

Access the PAINT program on your computer to help you decide upon your new color.
START
Programs
Accessories
Paint — Double click on any color at the bottom of the screen.
Choose «Define Custom Colors».
Select a color and/or use the arrows to achieve the desired color.
Copy down the RED, GREEN, BLUE numbers indicated. These
are the numbers needed to create your new Java color.

Create your new color by using the following code. Replace the R, G and B with the numbers pertaining to your new color.

Color myNewBlue = new Color (R, G, B); //creates your new color
g.setColor(myNewBlue); //accesses your new color (NO dot operator)

Creating Random Colors:

Create a random color with RGB values:

Источник

Оцените статью