List of usage examples for javax.swing JPanel getBackground
@Transient
public Color getBackground()
From source file:org.ut.biolab.medsavant.client.query.view.NumberSearchConditionEditorView.java
@Override public void loadViewFromSearchConditionParameters(String encoding) throws ConditionRestorationException { double[] selectedValues; if (encoding == null) { selectedValues = null;/*w w w.java 2s.c o m*/ } else { selectedValues = NumericConditionEncoder.unencodeConditions(encoding); } final double[] extremeValues = generator.getExtremeNumericValues(); this.removeAll(); if (extremeValues == null || (extremeValues[0] == 0 && extremeValues[1] == 0)) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(Box.createHorizontalGlue()); p.add(new JLabel("<html>All values are blank for this condition.</html>")); p.add(Box.createHorizontalGlue()); this.add(p); return; } setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel p = ViewUtil.getClearPanel(); ViewUtil.applyVerticalBoxLayout(p); JPanel labelPanel = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(labelPanel); labelPanel.add(Box.createHorizontalGlue()); labelPanel.add(new JLabel("Filtering variants where " + item.getName() + ": ")); labelPanel.add(Box.createHorizontalGlue()); ButtonGroup group = new ButtonGroup(); //JRadioButton isButton = new JRadioButton("is within the following range:"); //JRadioButton nullButton = new JRadioButton("is missing"); //group.add(isButton); //group.add(nullButton); final JCheckBox nullButton = new JCheckBox("include missing values"); JPanel bp = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(bp); p.add(labelPanel); p.add(bp); add(p); final DecimalRangeSlider slider = new DecimalRangeSlider(); slider.setMajorTickSpacing(5); slider.setMinorTickSpacing(1); final JTextField fromBox = new JTextField(); final JTextField toBox = new JTextField(); nullButton.setSelected(NumericConditionEncoder.encodesNull(encoding)); nullButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()), ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0], extremeValues[1], nullButton.isSelected()); } }); fromBox.setMaximumSize(new Dimension(10000, 24)); toBox.setMaximumSize(new Dimension(10000, 24)); fromBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24)); toBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24)); fromBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24)); toBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24)); fromBox.setHorizontalAlignment(JTextField.RIGHT); toBox.setHorizontalAlignment(JTextField.RIGHT); final JLabel fromLabel = new JLabel(); final JLabel toLabel = new JLabel(); ViewUtil.makeMini(fromLabel); ViewUtil.makeMini(toLabel); JPanel fromToContainer = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(fromToContainer); fromToContainer.add(Box.createHorizontalGlue()); fromToContainer.add(fromBox); fromToContainer.add(new JLabel(" - ")); fromToContainer.add(toBox); fromToContainer.add(Box.createHorizontalGlue()); JPanel minMaxContainer = ViewUtil.getClearPanel(); minMaxContainer.setLayout(new BoxLayout(minMaxContainer, BoxLayout.X_AXIS)); JPanel sliderContainer = ViewUtil.getClearPanel(); sliderContainer.setLayout(new BoxLayout(sliderContainer, BoxLayout.Y_AXIS)); sliderContainer.add(slider); JPanel nullValueContainer = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(nullValueContainer); nullValueContainer.add(Box.createHorizontalGlue()); nullValueContainer.add(nullButton); nullButton.setBackground(nullValueContainer.getBackground()); //fixes a windows issue. nullValueContainer.add(Box.createHorizontalGlue()); JPanel labelContainer = ViewUtil.getClearPanel(); labelContainer.setLayout(new BoxLayout(labelContainer, BoxLayout.X_AXIS)); labelContainer.add(fromLabel); labelContainer.add(Box.createHorizontalGlue()); labelContainer.add(toLabel); sliderContainer.add(labelContainer); minMaxContainer.add(Box.createHorizontalGlue()); minMaxContainer.add(sliderContainer); minMaxContainer.add(Box.createHorizontalGlue()); add(fromToContainer); add(minMaxContainer); add(nullValueContainer); add(Box.createVerticalBox()); slider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (slider.isEnabled()) { fromBox.setText(ViewUtil.numToString(slider.getLow())); toBox.setText(ViewUtil.numToString(slider.getHigh())); encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()), ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0], extremeValues[1], nullButton.isSelected()); } } }); final KeyListener keyListener = new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_ENTER) { Range selectedRage = new Range(getNumber(fromBox.getText()), getNumber(toBox.getText())); setSelectedValues(slider, fromBox, toBox, selectedRage); } } private double getNumber(String s) { try { return Double.parseDouble(s.replaceAll(",", "")); } catch (NumberFormatException ignored) { return 0; } } }; CaretListener caretListener = new CaretListener() { @Override public void caretUpdate(CaretEvent ce) { if (!isAdjustingSlider) { try { encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()), ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0], extremeValues[1], nullButton.isSelected()); } catch (Exception e) { } } } }; fromBox.addKeyListener(keyListener); toBox.addKeyListener(keyListener); fromBox.addCaretListener(caretListener); toBox.addCaretListener(caretListener); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { isAdjustingSlider = true; fromBox.setText(ViewUtil.numToString(slider.getLow())); toBox.setText(ViewUtil.numToString(slider.getHigh())); isAdjustingSlider = false; } }); JPanel bottomContainer = new JPanel(); bottomContainer.setLayout(new BoxLayout(bottomContainer, BoxLayout.X_AXIS)); bottomContainer.add(Box.createHorizontalGlue()); add(bottomContainer); setExtremeValues(slider, fromLabel, toLabel, fromBox, toBox, 0, new Range(extremeValues[0], extremeValues[1])); if (encoding != null) { double[] d = NumericConditionEncoder.unencodeConditions(encoding); setSelectedValues(slider, fromBox, toBox, new Range(d[0], d[1])); } }
From source file:ro.nextreports.designer.datasource.ConnectionDialog.java
private void create() { this.getContentPane().setLayout(new GridBagLayout()); this.addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { resize();/*w w w . j av a 2 s . c om*/ } }); JPanel p = new JPanel(new GridBagLayout()); backColor = p.getBackground(); mName = new JTextField(); mDriver = new JTextField(); //mDriver.setBackground(backColor); mURL = new JTextField(); //mURL.setBackground(backColor); mUser = new JTextField(); //mUser.setBackground(backColor); mPassword = new JPasswordField(); mPassword.setEchoChar('*'); //mPassword.setBackground(backColor); txaStatus = new JTextArea(); txaStatus.setEditable(false); txaStatus.setBackground(backColor); scr = new JScrollPane(txaStatus); scr.setSize(220, 50); scr.setBorder(new TitledBorder(STATUS)); types = new JComboBox(); types.addItemListener(this); urlFormatLabel = new JLabel(); Font font = urlFormatLabel.getFont().deriveFont(Font.BOLD, 10); urlFormatLabel.setFont(font); urlButton = new JButton(); urlButton.setPreferredSize(buttonDim); urlButton.setMinimumSize(buttonDim); urlButton.setMaximumSize(buttonDim); urlButton.setIcon(ImageUtil.getImageIcon("url_edit")); urlButton.setToolTipText(I18NSupport.getString("connection.dialog.tags.tooltip")); urlButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { editUrl(); } }); for (DriverTemplate template : templates) { types.addItem(template.getType()); } types.setSelectedItem(DEFAULT_DRIVER_TYPE); auto = new JCheckBox(I18NSupport.getString("connection.dialog.auto")); if (viewOnly) { mName.setEditable(false); types.setEnabled(false); mDriver.setEditable(false); mURL.setEditable(false); mUser.setEditable(false); mPassword.setEditable(false); urlButton.setEnabled(false); } p.add(new JLabel(I18NSupport.getString("connection.dialog.name")), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); p.add(mName, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); p.add(new JLabel(I18NSupport.getString("connection.dialog.type")), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); p.add(types, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); p.add(new JLabel(I18NSupport.getString("connection.dialog.driver")), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); p.add(mDriver, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); p.add(new JLabel(I18NSupport.getString("connection.dialog.url")), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); p.add(mURL, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); p.add(urlButton, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); if (!viewOnly) { p.add(urlFormatLabel, new GridBagConstraints(1, 4, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5), 0, 0)); } p.add(new JLabel(I18NSupport.getString("connection.dialog.user")), new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); p.add(mUser, new GridBagConstraints(1, 5, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); p.add(new JLabel(I18NSupport.getString("connection.dialog.password")), new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); p.add(mPassword, new GridBagConstraints(1, 6, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); if (!viewOnly) { p.add(auto, new GridBagConstraints(1, 7, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); } JButton okBtn, disBtn, drvBtn, addBtn, propBtn; okBtn = new JButton(I18NSupport.getString("connection.dialog.test"), ImageUtil.getImageIcon("database_connect")); okBtn.setMnemonic('T'); okBtn.setActionCommand("ConnectOk"); okBtn.setToolTipText(I18NSupport.getString("connection.dialog.test.tooltip")); okBtn.addActionListener(this); disBtn = new JButton(I18NSupport.getString("connection.dialog.disconnect"), ImageUtil.getImageIcon("database")); disBtn.setMnemonic('D'); disBtn.setActionCommand("Disconnect"); disBtn.setToolTipText(I18NSupport.getString("connection.dialog.disconnect")); disBtn.addActionListener(this); drvBtn = new JButton(I18NSupport.getString("connection.dialog.add.driver"), ImageUtil.getImageIcon("add_driver")); drvBtn.setMnemonic('A'); drvBtn.setActionCommand("AddDriver"); drvBtn.setToolTipText(I18NSupport.getString("connection.dialog.add.driver.tooltip")); drvBtn.addActionListener(this); propBtn = new JButton(I18NSupport.getString("connection.dialog.properties"), ImageUtil.getImageIcon("properties")); propBtn.setMnemonic('P'); propBtn.setActionCommand("Properties"); propBtn.setToolTipText(I18NSupport.getString("connection.dialog.properties.tooltip")); propBtn.addActionListener(this); addBtn = new JButton(ImageUtil.getImageIcon("database_export")); if (oldDataSource == null) { addBtn.setText(I18NSupport.getString("connection.dialog.save")); addBtn.setToolTipText(I18NSupport.getString("connection.dialog.save.tooltip")); addBtn.setMnemonic('S'); } else { addBtn.setText(I18NSupport.getString("connection.dialog.modify")); addBtn.setToolTipText(I18NSupport.getString("connection.dialog.modify.tooltip")); addBtn.setMnemonic('M'); } addBtn.setActionCommand("AddDataSource"); addBtn.addActionListener(this); JPanel btnPanel = new JPanel(); btnPanel.setLayout(new BoxLayout(btnPanel, BoxLayout.X_AXIS)); btnPanel.add(Box.createHorizontalGlue()); btnPanel.add(propBtn); btnPanel.add(Box.createRigidArea(new Dimension(5, 5))); btnPanel.add(okBtn); btnPanel.add(Box.createRigidArea(new Dimension(5, 5))); //btnPanel.add(disBtn); //btnPanel.add(Box.createRigidArea(new Dimension(5, 5))); btnPanel.add(addBtn); // btnPanel.add(Box.createRigidArea(new Dimension(5, 5))); // btnPanel.add(drvBtn); SwingUtil.equalizeButtonSizes(btnPanel); if (!viewOnly) { p.add(btnPanel, new GridBagConstraints(0, 8, 3, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); p.add(scr, new GridBagConstraints(0, 9, 3, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); } this.getContentPane().add(p, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); if (oldDataSource != null) { mName.setText(oldDataSource.getName()); types.setSelectedItem(oldDataSource.getType()); mDriver.setText(oldDataSource.getDriver()); mURL.setText(oldDataSource.getUrl()); mUser.setText(oldDataSource.getUser()); mPassword.setText(oldDataSource.getPassword()); } }
From source file:utybo.branchingstorytree.swing.visuals.AboutDialog.java
@SuppressWarnings("unchecked") public AboutDialog(OpenBSTGUI parent) { super(parent); setTitle(Lang.get("about.title")); setModalityType(ModalityType.APPLICATION_MODAL); JPanel banner = new JPanel(new FlowLayout(FlowLayout.CENTER)); banner.setBackground(OpenBSTGUI.OPENBST_BLUE); JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogoWhite", 48))); lblOpenbst.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); banner.add(lblOpenbst, "flowx,cell 0 0,alignx center"); getContentPane().add(banner, BorderLayout.NORTH); JPanel pan = new JPanel(); pan.setLayout(new MigLayout("insets 10, gap 10px", "[grow]", "[][][grow]")); getContentPane().add(pan, BorderLayout.CENTER); JLabel lblWebsite = new JLabel("https://utybo.github.io/BST/"); Font f = lblWebsite.getFont(); @SuppressWarnings("rawtypes") Map attrs = f.getAttributes(); attrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); lblWebsite.setFont(f.deriveFont(attrs)); lblWebsite.setForeground(OpenBSTGUI.OPENBST_BLUE); lblWebsite.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); lblWebsite.addMouseListener(new MouseAdapter() { @Override/*from www .j a v a 2s .co m*/ public void mouseClicked(MouseEvent e) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URL("https://utybo.github.io/BST/").toURI()); } catch (IOException | URISyntaxException e1) { OpenBST.LOG.warn("Exception when trying to open website", e1); } } } }); pan.add(lblWebsite, "cell 0 0,alignx center"); JLabel lblVersion = new JLabel(Lang.get("about.version").replace("$v", OpenBST.VERSION)); pan.add(lblVersion, "flowy,cell 0 1"); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBorder(new LineBorder(pan.getBackground().darker(), 1, false)); pan.add(scrollPane, "cell 0 2,grow"); JTextArea textArea = new JTextArea(); textArea.setMargin(new Insets(5, 5, 5, 5)); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setFont(new Font(textArea.getFont().getFontName(), Font.PLAIN, (int) (Icons.getScale() * 11))); try (InputStream in = getClass().getResourceAsStream("/utybo/branchingstorytree/swing/about.txt");) { textArea.setText(IOUtils.toString(in, StandardCharsets.UTF_8)); } catch (IOException ex) { OpenBST.LOG.warn("Loading about information failed", ex); } textArea.setEditable(false); textArea.setCaretPosition(0); scrollPane.setViewportView(textArea); JLabel lblTranslatedBy = new JLabel(Lang.get("author")); pan.add(lblTranslatedBy, "cell 0 1"); setSize((int) (Icons.getScale() * 450), (int) (Icons.getScale() * 400)); setLocationRelativeTo(parent); }