JUNG change color of an spceific

doktordoom

Mitglied
Hi,
at the moment, I'm trying to change the color of a specific vertex in JUNG. I know i can use the following function to change the color of all nodes. Is it possible to substitute v from the following line with a specific node.

vv.getRenderContext().setVertexFillPaintFunction(v -> Color.blue);

Or should i use transformer classes?

I checked out the jungrapht-visualization-master.

An example would be great. Thx!
 

looparda

Top Contributor
setVertexFillPaintFunction accepts Function as parameter. Therefore you can pass any logic.
e.g.:

Java:
   vv.getRenderContext().setVertexFillPaintFunction(v -> {
       if (v.id == 1) {
           return Color.red; 
       }
       return Color.yellow;
   });
 

Doktor_DOOM

Mitglied
Hi @looparda,
thanks you approach work well. One more question. How can i change the color of an list of specific vertexes ?
The following approach doesn't work.

Java:
      vv.getRenderContext().setVertexFillPaintFunction(v -> {
                if (v.equals("B0") && (v.equals("Z0") && (v.equals("V0")))) {
                  return Color.yellow;
                }
                return Color.green;
              }
      );
 

looparda

Top Contributor
You might want to use || instead.
To be more dynamic you can use List#contains to do something like this:
Java:
List<MyNode> highlightNodes = new ArrayList<>();
highlightNodes.add(v1);
highlightNodes.add(v2);
highlightNodes.add(v3);
vv.getRenderContext().setVertexFillPaintFunction(v -> highlightNodes.contains(v) ? Color.yellow : Color.green);
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
D JUNG Repaint function does not work AWT, Swing, JavaFX & SWT 2
D Start JUNG application with an Empty plot or visualisation AWT, Swing, JavaFX & SWT 1
C Jung - BinarySearchTree AWT, Swing, JavaFX & SWT 8
Z Methode bei Boolean change neu Ausführen AWT, Swing, JavaFX & SWT 9
T JComboBox before change AWT, Swing, JavaFX & SWT 3
X JButton color change AWT, Swing, JavaFX & SWT 2
G Change Lister und JTabbedPane AWT, Swing, JavaFX & SWT 2
Juelin setzen background color für selected Row im Tableview AWT, Swing, JavaFX & SWT 21
C JToggleButton disabled Text Color AWT, Swing, JavaFX & SWT 11
R AWT Color von Point AWT, Swing, JavaFX & SWT 1
C JCheckBox disabled text color AWT, Swing, JavaFX & SWT 9
K Color-Objekt erzeugen in CMYK AWT, Swing, JavaFX & SWT 2
M Swing JTable GroupableHeader Background Color AWT, Swing, JavaFX & SWT 4
E To get a color text on the TextArea AWT, Swing, JavaFX & SWT 4
E To get color text on the TextArea AWT, Swing, JavaFX & SWT 5
J JSlider Color Ticks AWT, Swing, JavaFX & SWT 1
Seikuassi SWING - (Hoffentlicher) simpler Color-Fehler AWT, Swing, JavaFX & SWT 4
F java.awt.Color AWT, Swing, JavaFX & SWT 8
S Rectangle Border Color AWT, Swing, JavaFX & SWT 13
K AWT Welche color benutzen? AWT, Swing, JavaFX & SWT 4
Y Globale Font-Color definieren AWT, Swing, JavaFX & SWT 5
J AWT setBackground(Color.orange) ist unter Win7 Aero nicht orange AWT, Swing, JavaFX & SWT 3
B Color String Code AWT, Swing, JavaFX & SWT 3
C Swing Button color transparent AWT, Swing, JavaFX & SWT 4
B Color.BLUE in String umwandeln AWT, Swing, JavaFX & SWT 4
W Verschiedene Foreground color in Combo SWT Auswahlliste AWT, Swing, JavaFX & SWT 5
lumo SWT Table Selection Color +Focus Out AWT, Swing, JavaFX & SWT 14
Developer_X Die Transparente Color AWT, Swing, JavaFX & SWT 8
A SWT - group - border color? AWT, Swing, JavaFX & SWT 4
V SWT Color Problem AWT, Swing, JavaFX & SWT 2
S Color in Cell AWT, Swing, JavaFX & SWT 2
O JTabbedPane - Selected Color? AWT, Swing, JavaFX & SWT 1
G Color AWT, Swing, JavaFX & SWT 5
S noobfrage: background color wird nicht angezeigt AWT, Swing, JavaFX & SWT 2
M setColor mit Fehler cannot fiend symbol (java.awt.Color) AWT, Swing, JavaFX & SWT 2
R SWT color Objekt AWT, Swing, JavaFX & SWT 4
L setBorder(BorderFactory.createLineBorder(Color,2) AWT, Swing, JavaFX & SWT 4
T Background Color JSpiner AWT, Swing, JavaFX & SWT 2
D ComboBox mit Farben aus java.awt.color AWT, Swing, JavaFX & SWT 4
L Farbregler - Werte als Zahl ausgeben - Color AWT, Swing, JavaFX & SWT 5
S java.awt.color Schriftfarbe AWT, Swing, JavaFX & SWT 3
T setBackground(Color) funktioniert nicht mit HTML? AWT, Swing, JavaFX & SWT 2
N java.awt.Color zu HTML Farbcode (JEditorPane) AWT, Swing, JavaFX & SWT 1
G standard blau (windows) != color.blue AWT, Swing, JavaFX & SWT 2
G Unsupported color conversion request AWT, Swing, JavaFX & SWT 3
S Hilfe bei Color(Helligkeit) AWT, Swing, JavaFX & SWT 4
S Object in Color umwandeln AWT, Swing, JavaFX & SWT 2
S Selection Color in JTabbedPane AWT, Swing, JavaFX & SWT 5
T Color lässt sich nicht verändern AWT, Swing, JavaFX & SWT 3
Z JPanels spiegeln und JLabel Background-color AWT, Swing, JavaFX & SWT 4

Ähnliche Java Themen


Oben