For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Hello Experts,
What is difference between doted line and bold line at data modeller, while showing many to 1 cardinality:
Thanks,
Rajneesh
247: public final void testSetBackground() { 248: Color color = Color.DARK_GRAY; 249: assertFalse(list.isBackgroundSet()); 250: aComp3.setBackground(color); 251: assertEquals(color, aComp1.getBackground()); 252: assertEquals(color, aComp2.getBackground()); 253: assertEquals(color, aComp3.getBackground()); 254: assertTrue("setBackground() is delegated to List", list 255: .isBackgroundSet()); 256: assertEquals(color, list.getBackground()); 257: }
import java.awt.*; import java.math.BigInteger; import java.util.Arrays; import java.util.Comparator; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; public class ColorList { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new ColorList().createGUI(); } }); } private void createGUI() { String[][] array = getArray(); // sort the array as you wish Arrays.sort(array, new Comparator<String[]>() { @Override public int compare(String[] o1, String[] o2) { return o1[1].compareTo(o2[1]); } }); // create the JList final JList list = new JList(array); // set some adequate renderer list.setCellRenderer(new DefaultListCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { DefaultListCellRenderer renderer = (DefaultListCellRenderer) super .getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); renderer.setText(((String[]) value)[1]); int color = new BigInteger(((String[]) value)[0], 16) .intValue(); renderer.setBackground(new Color(color)); renderer.setForeground(new Color(0xFFFFFFFF ^ color)); return renderer; } }); final JLabel demoLabel = new JLabel( "Display this text in the selected color", JLabel.CENTER); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { String[] selected = (String[]) list.getSelectedValue(); demoLabel.setForeground(new Color(new BigInteger(selected[0], 16).intValue())); } }); JFrame frame = new JFrame("ColorList"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(list), BorderLayout.LINE_START); frame.add(demoLabel, BorderLayout.CENTER); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } private String[][] getArray() { return new String[][] { { "000000", "Black" }, { "000080", "Navy Blue" }, { "0000C8", "Dark Blue" }, { "0000FF", "Blue" }, { "000741", "Stratos" }, { "00FF00", "Green" }, { "FF0000", "Red" }, { "FFFFF0", "Ivory" }, { "FFFFFF", "White" } }; } }
// was named paint() in awt version public void paintComponent(Graphics g) { Rectangle ulc; if (font == null) defineFont(g); // handle partial repaints of specific items if (partialOnly(g)) return; if (r != null) r = null; /* re-init to handle resizing of frame */ r = getBounds(); // for clean double-buffering super.paintComponent(g); maxI = calcMaxI(intensity); g.setColor(background); g.fillRect(0, 0, r.width, r.height); ... } /** *** There is no automatic update() with Swing. Therefor we need *** to patch our own into paint to avoid complete redraws. **/ public boolean partialOnly(Graphics g) { boolean imDone = true; if (wedgeOnly) { putDotOnWheel(g); paintWedge(g); drawSnake(g); drawSatSnake(g); updateLumaBars(g); wedgeOnly = false; } else if (wheelOnly) { // update the wedge's intensity dot and label putDotNearWedge(g); labelWedge(g); miscLabels(g); drawSnake(g); drawSatSnake(g); // update the GUI items having to do with intensity updateGUIintensity(g); updateLumaBars(g); paintWheel(g); putDotOnWheel(g); wheelOnly = false; } ... // etc else imDone = false; // allow full paint() return(imDone); }
public boolean partialOnly(Graphics g) { boolean imDone = true; if (resized > 0) { // should enter on 1 or 2 imDone = false; resized += 1; // clock thru two forced-full paints if (resized > 2) resized = 0; } ... }