private void setBorder(boolean isEnabled) { JTextField txfTmp = new JTextField(); if (isEnabled) setBorder(txfTmp.getBorder()); else { String strStyle = getAttribute(DISABLE); if (strStyle != null && strStyle.equals(m_arrStrDisAbl[1])) { setBorder(null); setBackground(Util.getBgColor()); } else { setBorder(txfTmp.getBorder()); setBackground(Global.NPCOLOR); } } }
public ServerDialog(OptionsDialog options_, Options opts_, CConn cc_) { super(true); cc = cc_; opts = opts_; options = options_; JLabel serverLabel = new JLabel("VNC server:", JLabel.RIGHT); String valueStr = null; if (opts.serverName != null) { String[] s = new String[1]; s[0] = opts.serverName; server = new JComboBox(s); } else if ((valueStr = UserPreferences.get("ServerDialog", "history")) != null) { server = new JComboBox(valueStr.split(",")); } else { server = new JComboBox(); } // Hack to set the left inset on editable JComboBox if (UIManager.getLookAndFeel().getID() == "Windows") { server.setBorder( BorderFactory.createCompoundBorder( server.getBorder(), BorderFactory.createEmptyBorder(0, 2, 0, 0))); } else if (UIManager.getLookAndFeel().getID() == "Metal") { ComboBoxEditor editor = server.getEditor(); JTextField jtf = (JTextField) editor.getEditorComponent(); jtf.setBorder(new CompoundBorder(jtf.getBorder(), new EmptyBorder(0, 2, 0, 0))); } server.setEditable(true); editor = server.getEditor(); editor .getEditorComponent() .addKeyListener( new KeyListener() { public void keyTyped(KeyEvent e) {} public void keyReleased(KeyEvent e) {} public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { server.insertItemAt(editor.getItem(), 0); server.setSelectedIndex(0); commit(); endDialog(); } } }); topPanel = new JPanel(new GridBagLayout()); Dialog.addGBComponent( new JLabel(VncViewer.logoIcon), topPanel, 0, 0, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(5, 5, 5, 15)); Dialog.addGBComponent( serverLabel, topPanel, 1, 0, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_END, new Insets(10, 0, 5, 5)); Dialog.addGBComponent( server, topPanel, 2, 0, 1, 1, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(10, 0, 5, 20)); optionsButton = new JButton("Options..."); aboutButton = new JButton("About..."); okButton = new JButton("Connect"); cancelButton = new JButton("Cancel"); buttonPanel = new JPanel(new GridBagLayout()); buttonPanel.setPreferredSize(new Dimension(350, 40)); Dialog.addGBComponent( aboutButton, buttonPanel, 0, 3, 1, 1, 0, 0, 0.8, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(0, 2, 0, 5)); Dialog.addGBComponent( optionsButton, buttonPanel, 1, 3, 1, 1, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(0, 2, 0, 5)); Dialog.addGBComponent( okButton, buttonPanel, 2, 3, 1, 1, 0, 0, 0.7, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(0, 2, 0, 5)); Dialog.addGBComponent( cancelButton, buttonPanel, 3, 3, 1, 1, 0, 0, 0.6, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(0, 2, 0, 5)); server.addActionListener(this); optionsButton.addActionListener(this); aboutButton.addActionListener(this); okButton.addActionListener(this); cancelButton.addActionListener(this); }