List of usage examples for javax.swing JPanel setBackground
@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.") public void setBackground(Color bg)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false);// w ww. j a v a 2 s . c o m frame.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); JPanel navigation_panel_wrap = new JPanel() { @Override public Dimension getPreferredSize() { return new Dimension(250, 700); } }; JPanel content_panel_wrap = new JPanel() { @Override public Dimension getPreferredSize() { return new Dimension(750, 700); } }; content_panel_wrap.setBackground(Color.green); navigation_panel_wrap.setBackground(Color.red); frame.add(navigation_panel_wrap); frame.add(content_panel_wrap); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setSize(300, 200);// w w w .jav a 2 s.c o m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton redButton = new JButton("Red"); JButton greenButton = new JButton("Green"); JButton blueButton = new JButton("Blue"); class Listener extends JPanel implements ActionListener { public void actionPerformed(ActionEvent event) { Color color; if (event.getSource() == redButton) { color = Color.red; redButton.setBackground(color); panel.setBackground(color); } else if (event.getSource() == greenButton) { color = Color.green; greenButton.setBackground(color); panel.setBackground(color); } else { color = Color.blue; blueButton.setBackground(color); panel.setBackground(color); } setBackground(color); repaint(); } } redButton.addActionListener(new Listener()); greenButton.addActionListener(new Listener()); blueButton.addActionListener(new Listener()); panel.add(redButton); panel.add(greenButton); panel.add(blueButton); frame.add(panel); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { int SIZE = 14; String FONT = "Dialog"; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane tp = new JTextPane(); tp.setFont(new Font(FONT, Font.PLAIN, SIZE)); tp.setPreferredSize(new Dimension(400, 300)); StyledDocument doc = tp.getStyledDocument(); Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style boldStyle = doc.addStyle("bold", defaultStyle); StyleConstants.setBold(boldStyle, true); String boldText = "this is bold test"; String plainText = "this is plain."; doc.insertString(doc.getLength(), boldText, boldStyle); doc.insertString(doc.getLength(), plainText, defaultStyle); JPanel panel = new JPanel(); panel.add(tp);/*from www .ja va 2 s . co m*/ JComboBox<String> zoomCombo = new JComboBox<String>( new String[] { "0.75", "1.00", "1.50", "1.75", "2.00" }); zoomCombo.addActionListener(e -> { String s = (String) zoomCombo.getSelectedItem(); double scale = new Double(s).doubleValue(); int size = (int) (SIZE * scale); tp.setFont(new Font(FONT, Font.PLAIN, size)); }); zoomCombo.setSelectedItem("1.00"); JPanel optionsPanel = new JPanel(); optionsPanel.add(zoomCombo); panel.setBackground(Color.WHITE); frame.add(panel, BorderLayout.CENTER); frame.add(optionsPanel, BorderLayout.NORTH); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static JComponent makeUI() { JPanel p = new JPanel(); p.setBackground(new Color(.5f, .5f, .5f, .5f)); p.add(new JComboBox<String>(new String[] { "aaa", "bb", "c" })); JComboBox c = new JComboBox<String>(new String[] { "aaa", "bb", "c" }); p.add(c);//w w w . j av a 2s .c om return p; }
From source file:JListBackground.java
public static void addComponentsToPane(Container pane) { String[] bruteForceCode = { "int count = 0", "int m = mPattern.length();", "int n = mSource .length();", "outer:", " ++count;", " }", " return count;", "}" }; JList list = new JList(bruteForceCode); Border etch = BorderFactory.createEtchedBorder(); list.setBorder(BorderFactory.createTitledBorder(etch, "Brute Force Code")); JPanel listPanel = new JPanel(); listPanel.add(list);//from ww w. ja va 2 s .c o m listPanel.setBackground(lightBlue); list.setBackground(lightBlue); pane.add(listPanel, BorderLayout.CENTER); pane.setBackground(lightBlue); }
From source file:Main.java
public static void main_helper(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setSize(300, 300);/*from w w w.j a v a 2 s . c om*/ f.setUndecorated(true); f.getRootPane().setWindowDecorationStyle(JRootPane.FRAME); JPanel panel = new JPanel(); panel.setBackground(java.awt.Color.white); f.setContentPane(panel); MetalLookAndFeel.setCurrentTheme(new MyDefaultMetalTheme()); try { UIManager.setLookAndFeel(new MetalLookAndFeel()); } catch (Exception e) { e.printStackTrace(); } SwingUtilities.updateComponentTreeUI(f); f.setVisible(true); }
From source file:Main.java
/** * Returns a "warning"-colored panel with given message. * /*www.j av a 2 s .co m*/ * @param context * @param message * @return */ public static JPanel constructWarningPanel(String message) { JPanel p = new JPanel(); JLabel l = new JLabel(message); // "magical" color p.setBackground(new Color(240, 40, 70)); p.add(l); return p; }
From source file:cimat.tesis.sna.visualization.ShowLayouts.java
private static JPanel getGraphPanel() { g_array = (Graph<? extends Object, ? extends Object>[]) new Graph<?, ?>[graph_names.length]; Factory<Graph<Integer, Number>> graphFactory = new Factory<Graph<Integer, Number>>() { public Graph<Integer, Number> create() { return new SparseMultigraph<Integer, Number>(); }// w w w .j a va 2 s.c om }; Factory<Integer> vertexFactory = new Factory<Integer>() { int count; public Integer create() { return count++; } }; Factory<Number> edgeFactory = new Factory<Number>() { int count; public Number create() { return count++; } }; g_array[0] = TestGraphs.createTestGraph(false); g_array[1] = MixedRandomGraphGenerator.generateMixedRandomGraph(graphFactory, vertexFactory, edgeFactory, new HashMap<Number, Number>(), 20, true, new HashSet<Integer>()); g_array[2] = TestGraphs.getDemoGraph(); g_array[3] = TestGraphs.createDirectedAcyclicGraph(4, 4, 0.3); g_array[4] = TestGraphs.getOneComponentGraph(); g_array[5] = TestGraphs.createChainPlusIsolates(18, 5); g_array[6] = TestGraphs.createChainPlusIsolates(0, 20); Graph<? extends Object, ? extends Object> g = g_array[4]; // initial graph final VisualizationViewer<Integer, Number> vv = new VisualizationViewer<Integer, Number>(new FRLayout(g)); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow)); final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(graphMouse); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Layout<Integer, Number> layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { // if(layout instanceof IterativeContext) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener()); JPanel jp = new JPanel(); jp.setBackground(Color.WHITE); jp.setLayout(new BorderLayout()); jp.add(vv, BorderLayout.CENTER); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); JPanel control_panel = new JPanel(new GridLayout(2, 1)); JPanel topControls = new JPanel(); JPanel bottomControls = new JPanel(); control_panel.add(topControls); control_panel.add(bottomControls); jp.add(control_panel, BorderLayout.NORTH); final JComboBox graph_chooser = new JComboBox(graph_names); graph_chooser.addActionListener(new GraphChooser(jcb)); topControls.add(jcb); topControls.add(graph_chooser); bottomControls.add(plus); bottomControls.add(minus); bottomControls.add(modeBox); bottomControls.add(reset); return jp; }
From source file:edu.uci.ics.jung.samples.ShowLayouts.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private static JPanel getGraphPanel() { g_array = (Graph<? extends Object, ? extends Object>[]) new Graph<?, ?>[graph_names.length]; Factory<Graph<Integer, Number>> graphFactory = new Factory<Graph<Integer, Number>>() { public Graph<Integer, Number> create() { return new SparseMultigraph<Integer, Number>(); }//w w w. j ava 2 s .c o m }; Factory<Integer> vertexFactory = new Factory<Integer>() { int count; public Integer create() { return count++; } }; Factory<Number> edgeFactory = new Factory<Number>() { int count; public Number create() { return count++; } }; g_array[0] = TestGraphs.createTestGraph(false); g_array[1] = MixedRandomGraphGenerator.generateMixedRandomGraph(graphFactory, vertexFactory, edgeFactory, new HashMap<Number, Number>(), 20, true, new HashSet<Integer>()); g_array[2] = TestGraphs.getDemoGraph(); g_array[3] = TestGraphs.createDirectedAcyclicGraph(4, 4, 0.3); g_array[4] = TestGraphs.getOneComponentGraph(); g_array[5] = TestGraphs.createChainPlusIsolates(18, 5); g_array[6] = TestGraphs.createChainPlusIsolates(0, 20); Graph<? extends Object, ? extends Object> g = g_array[4]; // initial graph final VisualizationViewer<Integer, Number> vv = new VisualizationViewer<Integer, Number>(new FRLayout(g)); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow)); final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(graphMouse); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Layout<Integer, Number> layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { // if(layout instanceof IterativeContext) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener()); JPanel jp = new JPanel(); jp.setBackground(Color.WHITE); jp.setLayout(new BorderLayout()); jp.add(vv, BorderLayout.CENTER); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); JPanel control_panel = new JPanel(new GridLayout(2, 1)); JPanel topControls = new JPanel(); JPanel bottomControls = new JPanel(); control_panel.add(topControls); control_panel.add(bottomControls); jp.add(control_panel, BorderLayout.NORTH); final JComboBox graph_chooser = new JComboBox(graph_names); graph_chooser.addActionListener(new GraphChooser(jcb)); topControls.add(jcb); topControls.add(graph_chooser); bottomControls.add(plus); bottomControls.add(minus); bottomControls.add(modeBox); bottomControls.add(reset); return jp; }
From source file:com.liveperson.infra.akka.actorx.ui.DisplayGraph.java
public static JPanel getGraphPanel() { final VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(new FRLayout(graph)); vv.setBackground(Color.white); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(vv.getPickedVertexState(), Color.blue, Color.yellow)); vv.getRenderContext().setVertexLabelTransformer(new Transformer<String, String>() { @Override//from w ww . j av a 2s .com public String transform(String s) { return getClassName(s); } }); vv.setVertexToolTipTransformer(new Transformer<String, String>() { @Override public String transform(String s) { return getClassName(s); } }); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<String>(vv.getPickedEdgeState(), Color.black, Color.green)); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<String, String>()); vv.setEdgeToolTipTransformer(new Transformer<String, String>() { @Override public String transform(String edge) { StringBuffer buffer = new StringBuffer(); buffer.append("<html>"); int index = edge.indexOf(Main.DELIMITER); String fromActor = edge.substring(0, index); String toActor = edge.substring(index + Main.DELIMITER.length()); Map<String, Set<String>> connections = castConnectionList.get(fromActor); Set<String> messages = connections.get(toActor); for (String msg : messages) { buffer.append("<p>").append(getClassName(msg)); } buffer.append("</html>"); return buffer.toString(); } }); ToolTipManager.sharedInstance().setDismissDelay(60000); final DefaultModalGraphMouse<String, String> graphMouse = new DefaultModalGraphMouse<String, String>(); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(graphMouse); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Layout<String, String> layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { // if(layout instanceof IterativeContext) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); JPanel jp = new JPanel(); jp.setBackground(Color.WHITE); jp.setLayout(new BorderLayout()); jp.add(vv, BorderLayout.CENTER); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); JPanel control_panel = new JPanel(new GridLayout(2, 1)); JPanel topControls = new JPanel(); JPanel bottomControls = new JPanel(); control_panel.add(topControls); control_panel.add(bottomControls); jp.add(control_panel, BorderLayout.NORTH); topControls.add(jcb); bottomControls.add(plus); bottomControls.add(minus); bottomControls.add(reset); return jp; }