Example usage for javax.swing JLabel setOpaque

List of usage examples for javax.swing JLabel setOpaque

Introduction

In this page you can find the example usage for javax.swing JLabel setOpaque.

Prototype

@BeanProperty(expert = true, description = "The component's opacity")
public void setOpaque(boolean isOpaque) 

Source Link

Document

If true the component paints every pixel within its bounds.

Usage

From source file:DesktopManagerDemo.java

public void newFrame() {
    JInternalFrame jif = new JInternalFrame("Frame " + m_count, true, true, true, true);
    jif.setBounds(20 * (m_count % 10) + m_tencount * 80, 20 * (m_count % 10), 200, 200);
    JLabel label = new JLabel();
    label.setBackground(Color.white);
    label.setOpaque(true);
    jif.getContentPane().add(label);/*from   w w  w .  j a v  a2  s . c  om*/
    m_desktop.add(jif);
    try {
        jif.setSelected(true);
    } catch (PropertyVetoException pve) {
        System.out.println("Could not select " + jif.getTitle());
    }
    m_count++;
    if (m_count % 10 == 0) {
        if (m_tencount < 3)
            m_tencount++;
        else
            m_tencount = 0;
    }
}

From source file:net.nosleep.superanalyzer.analysis.views.SummaryView.java

private void addStatTriple(JPanel panel, StringTriple triple) {

    JLabel wordLabel = new JLabel(triple.Name + ": ");
    wordLabel.setOpaque(false);
    wordLabel.setFont(Theme.getFont(12));
    wordLabel.setHorizontalAlignment(JLabel.RIGHT);
    panel.add(wordLabel);/* ww  w  .j  a  v  a  2s  . co  m*/

    JLabel wordField = new JLabel();
    wordField.setOpaque(false);
    wordField.setFont(Theme.getBoldFont(12));
    wordField.setBorder(new javax.swing.border.EmptyBorder(1, 1, 1, 1));
    wordField.setForeground(Theme.getColorSet()[0]);
    panel.add(wordField);

    wordField.setText(triple.Value);
    wordField.setToolTipText(Misc.getTooltip(triple.Info));
}

From source file:DragColorDemo.java

public DragColorDemo() {
    super(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    JColorChooser chooser = new JColorChooser();
    chooser.setDragEnabled(true);/*from  w  w  w  . j  a  v a 2s .co  m*/
    add(chooser, BorderLayout.PAGE_START);

    //Create the color transfer handler.
    colorHandler = new ColorTransferHandler();

    //Create a matrix of 9 buttons.
    JPanel buttonPanel = new JPanel(new GridLayout(3, 3));
    for (int i = 0; i < 9; i++) {
        JButton tmp = new JButton("Button " + i);
        tmp.setTransferHandler(colorHandler);
        buttonPanel.add(tmp);
    }
    add(buttonPanel, BorderLayout.CENTER);

    //Create a check box.
    toggleForeground = new JCheckBox("Change the foreground color.");
    toggleForeground.setSelected(true);
    toggleForeground.addActionListener(this);
    JPanel textPanel = new JPanel(new BorderLayout());
    textPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    textPanel.add(toggleForeground, BorderLayout.PAGE_START);

    //Create a label.
    JLabel label = new JLabel("Change the color of any button or this label by dropping a color.");
    label.setTransferHandler(colorHandler);
    label.setOpaque(true); //So the background color can be changed.
    textPanel.add(label, BorderLayout.PAGE_END);
    add(textPanel, BorderLayout.PAGE_END);
}

From source file:be.ac.ua.comp.scarletnebula.gui.ServerCellRenderer.java

private JLabel getServernameComponent(final Server server, final Color foreground) {
    final JLabel label = new JLabel(server.getFriendlyName(), getServerIcon(server), SwingConstants.LEFT);
    label.setOpaque(false);

    label.setForeground(foreground);/*from  w w w.j av a2  s .c  o  m*/
    return label;
}

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 w  ww . j av 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:com.floreantpos.ui.views.LoginView.java

private LoginView() {
    setLayout(new BorderLayout(5, 5));

    width = PosUIManager.getSize(600);// ww  w.ja  v  a  2 s.c  o  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:de.codesourcery.eve.skills.ui.utils.CalendarWidget.java

protected void setup() {

    // draw heading
    for (int x = 0; x < 7; x++) {
        final String day = getWeekDayName(getDateFor(x, 0));
        final JLabel label = new JLabel(day, JLabel.CENTER);
        label.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
        label.setOpaque(true);
        add(label, new ConstraintsBuilder(x, 0).resizeHorizontally().weightY(0).end());
    }//from w w  w .ja  v a2 s  . c  o  m

    // draw 4x7 buttons
    for (int y = 0; y < 4; y++) {
        for (int x = 0; x < 7; x++) {
            buttons[y][x] = new MyButton(x, y);
            add(buttons[y][x], new ConstraintsBuilder(x, 1 + y).end());
        }
    }
}

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);/*from  w ww. j a v a2s . c om*/
        head.setOpaque(true);
        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: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  ww w .  j  a  v  a  2  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: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 w ww  . j a  v  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);
}