List of usage examples for javax.swing JLabel setBackground
@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.") public void setBackground(Color bg)
From source file:com.game.ui.views.MapEditor.java
public void generateGUI() throws IOException { setDefaultCloseOperation(DISPOSE_ON_CLOSE); // setResizable(false); JMenuBar menubar = new JMenuBar(); ImageIcon icon = null;/*from ww w . j a v a 2 s.c o m*/ try { icon = GameUtils.shrinkImage("save.png", 20, 20); } catch (IOException e) { System.out.println("Dialog : showDialogForMap(): Exception occured :" + e); e.printStackTrace(); } JMenu file = new JMenu("File"); JMenuItem save = new JMenuItem("Save", icon); save.setToolTipText("Save Map Information"); save.setActionCommand("Save Map"); save.addActionListener(this); file.add(save); menubar.add(file); setJMenuBar(menubar); JPanel topPanel = new JPanel(); topPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); topPanel.setLayout(new GridBagLayout()); JLabel headerLbl = new JLabel("Legend : "); headerLbl.setFont(new Font("Times New Roman", Font.BOLD, 15)); JLabel lbl1 = new JLabel(); lbl1.setPreferredSize(new Dimension(50, 20)); lbl1.setBackground(Configuration.pathColor); lbl1.setOpaque(true); JLabel lbl2 = new JLabel("- Represents the path."); JLabel lbl3 = new JLabel(); lbl3.setPreferredSize(new Dimension(50, 20)); lbl3.setBackground(Configuration.enemyColor); lbl3.setOpaque(true); JLabel lbl4 = new JLabel("- Represents the path with monsters"); JLabel lbl5 = new JLabel(); lbl5.setPreferredSize(new Dimension(50, 20)); lbl5.setBackground(Configuration.startPointColor); lbl5.setOpaque(true); JLabel lbl6 = new JLabel("- Represents the starting point in the path"); JLabel lbl7 = new JLabel(); lbl7.setBackground(Configuration.endPointColor); lbl7.setOpaque(true); lbl7.setPreferredSize(new Dimension(50, 20)); JLabel lbl8 = new JLabel("- Ending point in the path"); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.weightx = 1; c.weighty = 0; c.insets = new Insets(5, 5, 5, 5); c.gridwidth = 2; topPanel.add(headerLbl, c); c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 1; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.ipadx = 5; c.ipady = 5; topPanel.add(lbl1, c); c.gridx = 1; c.anchor = GridBagConstraints.FIRST_LINE_START; topPanel.add(lbl2, c); c.gridx = 0; c.gridy = 2; topPanel.add(lbl3, c); c.gridx = 1; topPanel.add(lbl4, c); c.gridx = 0; c.gridy = 3; topPanel.add(lbl5, c); c.gridx = 1; topPanel.add(lbl6, c); c.gridx = 0; c.gridy = 4; topPanel.add(lbl7, c); c.gridx = 1; topPanel.add(lbl8, c); add(topPanel, BorderLayout.NORTH); bottomPanel = new JPanel(); add(bottomPanel, BorderLayout.CENTER); bottomPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); // bottomPanel.add(new JButton("kaushik")); pack(); setExtendedState(JFrame.MAXIMIZED_BOTH); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); setMaximizedBounds(env.getMaximumWindowBounds()); setVisible(true); callDialogForUsersInput(); }
From source file:Main.java
public Main() { mainPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT)); mainPanel.setLayout(null);/*w w w. ja v a 2 s . c o m*/ MyMouseAdapter myMouseAdapter = new MyMouseAdapter(); for (int i = 0; i < LABEL_STRINGS.length; i++) { JLabel label = new JLabel(LABEL_STRINGS[i], SwingConstants.CENTER); label.setSize(new Dimension(LBL_WIDTH, LBL_HEIGHT)); label.setOpaque(true); Random random = new Random(); label.setLocation(random.nextInt(WIDTH - LBL_WIDTH), random.nextInt(HEIGHT - LBL_HEIGHT)); label.setBackground( new Color(150 + random.nextInt(105), 150 + random.nextInt(105), 150 + random.nextInt(105))); label.addMouseListener(myMouseAdapter); label.addMouseMotionListener(myMouseAdapter); mainPanel.add(label); } }
From source file:de.iew.imageupload.widgets.ContentPane.java
public void registerImageFile(File file) { try {//w ww . j a v a 2 s . c om ImageIcon imageIcon = new ImageIcon(file.getAbsolutePath()); JLabel imageLabel = new JLabel(imageIcon, JLabel.CENTER); imageLabel.setPreferredSize(new Dimension(100, 100)); imageLabel.setSize(new Dimension(100, 100)); imageLabel.addMouseListener(this.imageMouseClickHandler); imageLabel.setBackground(Color.WHITE); imageLabel.setBorder(new EmptyBorder(10, 10, 10, 10)); imageLabel.putClientProperty("Image File", file); this.imageGridPane.add(imageLabel); this.imageGridPane.revalidate(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
private JPanel createComboLabelPanel(int index, JComboBox<ComboColor> combo) { JPanel panel = new JPanel(); JLabel label = new JLabel(SIGNAL + " " + index); label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); label.setOpaque(true);/*from ww w. j a v a 2 s . co m*/ combo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { ComboColor cColor = (ComboColor) combo.getSelectedItem(); label.setBackground(cColor.getColor()); } }); panel.add(label); panel.add(combo); return panel; }
From source file:de.tor.tribes.ui.components.DatePicker.java
private void init() { //build Header for (int i = 0; i < 7; i++) { JLabel head = new JLabel(dayNames[i]); head.setBackground(GRAY); head.setOpaque(true);/*from w w w.j av a 2 s.c om*/ head.setPreferredSize(new Dimension(20, 20)); head.setMinimumSize(new Dimension(20, 20)); head.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.PAGE_START; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = i; gbc.gridy = 0; gbc.insets = new Insets(2, 2, 6, 2); gbc.ipadx = 0; gbc.ipady = 0; gbc.weightx = 1.0; gbc.weighty = 0.0; jPanelDaySelection.add(head, gbc); } daysInMonth = new CrossedLabel[WEEKS_TO_SHOW][7]; datesInMonth = new Date[WEEKS_TO_SHOW][7]; for (int i = 0; i < WEEKS_TO_SHOW; i++) { for (int j = 0; j < 7; j++) { daysInMonth[i][j] = new CrossedLabel(); daysInMonth[i][j].setPreferredSize(new Dimension(20, 20)); daysInMonth[i][j].setMinimumSize(new Dimension(20, 20)); daysInMonth[i][j].setHorizontalAlignment(javax.swing.SwingConstants.CENTER); daysInMonth[i][j].addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseevent) { dayClicked(mouseevent); } }); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.PAGE_START; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = j; gbc.gridy = i + 1; gbc.insets = new Insets(2, 2, 2, 2); gbc.ipadx = 0; gbc.ipady = 0; gbc.weightx = 1.0; gbc.weighty = 0.0; jPanelDaySelection.add(daysInMonth[i][j], gbc); } } buildCalendar(); }
From source file:com.floreantpos.ui.views.LoginView.java
private LoginView() { setLayout(new BorderLayout(5, 5)); width = PosUIManager.getSize(600);//w w w. ja v a2 s . co m height = PosUIManager.getSize(100); centerPanel.setLayout(new MigLayout("al center center", "sg fill", String.valueOf(height))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ JLabel titleLabel = new JLabel(IconFactory.getIcon("/ui_icons/", "title.png")); //$NON-NLS-1$ //$NON-NLS-2$ titleLabel.setOpaque(true); titleLabel.setBackground(Color.WHITE); JPanel panel = new JPanel(new BorderLayout()); panel.add(titleLabel, BorderLayout.CENTER); panel.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH); add(panel, BorderLayout.NORTH); add(createCenterPanel(), BorderLayout.CENTER); }
From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterListEdtDlg.java
@Override public void createUI() { super.createUI(); CellConstraints cc = new CellConstraints(); // get formatters for field List<UIFieldFormatterIFace> fmtrs = new Vector<UIFieldFormatterIFace>(uiFieldFormatterMgrCache .getFormatterList(fieldInfo.getTableInfo().getClassObj(), fieldInfo.getName())); Collections.sort(fmtrs, new Comparator<UIFieldFormatterIFace>() { public int compare(UIFieldFormatterIFace o1, UIFieldFormatterIFace o2) { return o1.getName().compareTo(o2.getName()); }//from w w w . jav a2 s . c o m }); // table and field titles PanelBuilder tblInfoPB = new PanelBuilder( new FormLayout("r:p,2px,f:p:g", "p,2px,p,2px,p,10px")/*, new FormDebugPanel()*/); String typeStr = fieldInfo.getType(); typeStr = typeStr.indexOf('.') > -1 ? StringUtils.substringAfterLast(fieldInfo.getType(), ".") : typeStr; JLabel tableTitleLbl = createLabel(getResourceString("FFE_TABLE") + ":"); JLabel tableTitleValueLbl = createLabel(fieldInfo.getTableInfo().getTitle()); tableTitleValueLbl.setBackground(Color.WHITE); tableTitleValueLbl.setOpaque(true); JLabel fieldTitleLbl = createLabel(getResourceString("FFE_FIELD") + ":"); JLabel fieldTitleValueLbl = createLabel(fieldInfo.getTitle()); fieldTitleValueLbl.setBackground(Color.WHITE); fieldTitleValueLbl.setOpaque(true); //JLabel fieldTypeLbl = createLabel(getResourceString("FFE_TYPE") + ":"); //JLabel fieldTypeValueLbl = createLabel(typeStr); //fieldTypeValueLbl.setBackground(Color.WHITE); //fieldTypeValueLbl.setOpaque(true); JLabel fieldLengthLbl = createLabel(getResourceString("FFE_LENGTH") + ":"); JLabel fieldLengthValueLbl = createLabel(Integer.toString(fieldInfo.getLength())); fieldLengthValueLbl.setBackground(Color.WHITE); fieldLengthValueLbl.setOpaque(true); int y = 1; tblInfoPB.add(tableTitleLbl, cc.xy(1, y)); tblInfoPB.add(tableTitleValueLbl, cc.xy(3, y)); y += 2; tblInfoPB.add(fieldTitleLbl, cc.xy(1, y)); tblInfoPB.add(fieldTitleValueLbl, cc.xy(3, y)); y += 2; //tblInfoPB.add(fieldTypeLbl, cc.xy(1, y)); //tblInfoPB.add(fieldTypeValueLbl, cc.xy(3, y)); y += 2; tblInfoPB.add(fieldLengthLbl, cc.xy(1, y)); tblInfoPB.add(fieldLengthValueLbl, cc.xy(3, y)); y += 2; DefaultListModel listModel = new DefaultListModel(); // add available formatters for (UIFieldFormatterIFace format : fmtrs) { listModel.addElement(format); } formatList = createList(listModel); formatList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //formatList.setCellRenderer(new FmtListRenderer()); hookFormatListSelectionListener(); hookFormatListMouseListener(); ActionListener deleteListener = new ActionListener() { public void actionPerformed(ActionEvent e) { deleteFormatter(); } }; ActionListener editListener = new ActionListener() { public void actionPerformed(ActionEvent e) { editFormatter((UIFieldFormatter) formatList.getSelectedValue(), false); } }; ActionListener addListener = new ActionListener() { public void actionPerformed(ActionEvent e) { addFormatter(); } }; ActionListener defListener = new ActionListener() { public void actionPerformed(ActionEvent e) { setAsDefFormatter(); } }; dedaPanel = new DefEditDeleteAddPanel(defListener, editListener, deleteListener, addListener, "FFE_DEF", "FFE_EDT", "FFE_DEL", "FFE_ADD"); dedaPanel.getAddBtn().setEnabled(true); PanelBuilder pb = new PanelBuilder(new FormLayout("f:max(250px;p):g", "p,4px,p,2px,f:p:g,4px,p")); y = 1; pb.add(tblInfoPB.getPanel(), cc.xy(1, y)); y += 2; pb.add(createI18NLabel("FFE_AVAILABLE_FORMATS", SwingConstants.LEFT), cc.xy(1, y)); y += 2; pb.add(createScrollPane(formatList), cc.xy(1, y)); y += 2; pb.add(dedaPanel, cc.xy(1, y)); y += 2; pb.setDefaultDialogBorder(); //pb.getPanel().setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); contentPanel = pb.getPanel(); mainPanel.add(contentPanel, BorderLayout.CENTER); okBtn.setEnabled(false); pack(); }
From source file:com.opendoorlogistics.studio.tables.grid.HeaderCellRenderer.java
/** * @param value/* w ww . j ava 2 s . c om*/ * @param isSelected */ protected void prepareLabel(Object value, boolean isSelected, boolean italics, JLabel label) { StringBuilder builder = new StringBuilder(); if (value != null) { builder.append("<html><strong>"); if (italics) { builder.append("<em>"); } builder.append(StringEscapeUtils.escapeHtml4(value.toString())); if (italics) { builder.append("</em>"); } builder.append("</strong></html>"); } label.setText(builder.toString()); if (isSelected) { label.setBackground(selectedColour); } else { label.setBackground(disabledColour); } }
From source file:Main.java
public Main() { super("JScrollPane Demo"); JScrollPane scrollPane = new JScrollPane(label); JLabel[] corners = new JLabel[4]; for (int i = 0; i < 4; i++) { corners[i] = new JLabel(); corners[i].setBackground(Color.white); corners[i].setOpaque(true);/*from ww w . j av a 2s . c o m*/ } JLabel rowheader = new JLabel() { public void paintComponent(Graphics g) { super.paintComponent(g); Rectangle rect = g.getClipBounds(); for (int i = 50 - (rect.y % 50); i < rect.height; i += 50) { g.drawLine(0, rect.y + i, 3, rect.y + i); g.drawString("" + (rect.y + i), 6, rect.y + i + 3); } } public Dimension getPreferredSize() { return new Dimension(25, (int) label.getPreferredSize().getHeight()); } }; rowheader.setBackground(Color.white); rowheader.setOpaque(true); JLabel columnheader = new JLabel() { public void paintComponent(Graphics g) { super.paintComponent(g); Rectangle r = g.getClipBounds(); for (int i = 50 - (r.x % 50); i < r.width; i += 50) { g.drawLine(r.x + i, 0, r.x + i, 3); g.drawString("" + (r.x + i), r.x + i - 10, 16); } } public Dimension getPreferredSize() { return new Dimension((int) label.getPreferredSize().getWidth(), 25); } }; columnheader.setBackground(Color.white); columnheader.setOpaque(true); scrollPane.setRowHeaderView(rowheader); scrollPane.setColumnHeaderView(columnheader); scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, corners[0]); scrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, corners[1]); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corners[2]); scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, corners[3]); getContentPane().add(scrollPane); setSize(400, 300); setVisible(true); }
From source file:HeaderDemo.java
public HeaderDemo() { super("JScrollPane Demo"); JScrollPane scrollPane = new JScrollPane(label); JLabel[] corners = new JLabel[4]; for (int i = 0; i < 4; i++) { corners[i] = new JLabel(); corners[i].setBackground(Color.white); corners[i].setOpaque(true);// w w w .j a va 2s . co m } JLabel rowheader = new JLabel() { public void paintComponent(Graphics g) { super.paintComponent(g); Rectangle rect = g.getClipBounds(); for (int i = 50 - (rect.y % 50); i < rect.height; i += 50) { g.drawLine(0, rect.y + i, 3, rect.y + i); g.drawString("" + (rect.y + i), 6, rect.y + i + 3); } } public Dimension getPreferredSize() { return new Dimension(25, (int) label.getPreferredSize().getHeight()); } }; rowheader.setBackground(Color.white); rowheader.setOpaque(true); JLabel columnheader = new JLabel() { public void paintComponent(Graphics g) { super.paintComponent(g); Rectangle r = g.getClipBounds(); for (int i = 50 - (r.x % 50); i < r.width; i += 50) { g.drawLine(r.x + i, 0, r.x + i, 3); g.drawString("" + (r.x + i), r.x + i - 10, 16); } } public Dimension getPreferredSize() { return new Dimension((int) label.getPreferredSize().getWidth(), 25); } }; columnheader.setBackground(Color.white); columnheader.setOpaque(true); scrollPane.setRowHeaderView(rowheader); scrollPane.setColumnHeaderView(columnheader); scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, corners[0]); scrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, corners[1]); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corners[2]); scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, corners[3]); getContentPane().add(scrollPane); setSize(400, 300); setVisible(true); }