public class MyListCellRenderer implements ListCellRenderer { private JLabel jlblCell = new JLabel(" ", JLabel.LEFT); private Border lineBorder = BorderFactory.createLineBorder(Color.black, 1); private Border emptyBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2); /** Implement this method in ListCellRenderer */ public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Object[] pair = (Object[]) value; // Cast value into an array jlblCell.setOpaque(true); jlblCell.setIcon((ImageIcon) pair[0]); jlblCell.setText(pair[1].toString()); if (isSelected) { jlblCell.setForeground(list.getSelectionForeground()); jlblCell.setBackground(list.getSelectionBackground()); } else { jlblCell.setForeground(list.getForeground()); jlblCell.setBackground(list.getBackground()); } jlblCell.setBorder(cellHasFocus ? lineBorder : emptyBorder); return jlblCell; } }
public AddNewStudent() // constructor { // initializing buttons btnok = new JButton("OK"); btnok.addActionListener(this); btnexit = new JButton("Exit"); btnexit.addActionListener(this); btnaddnew = new JButton("AddNew"); btnaddnew.addActionListener(this); // initializing textfields tf1 = new JTextField(12); tf2 = new JTextField(12); // initializing labels lblname = new JLabel("Name:"); lbladd = new JLabel("Address:"); lblmsg = new JLabel("", JLabel.CENTER); // initializing panels p1 = new JPanel(); p2 = new JPanel(); p3 = new JPanel(); psouth = new JPanel(); // adding buttons and label to panel p1 // setting flowlayout p1.setLayout(new FlowLayout()); p1.add(btnok); p1.add(btnexit); p1.add(btnaddnew); // adding lblmsg to panel p3 p3.add(lblmsg); // adding both the panels to new panel,psouth // settin layout 2:1 psouth.setLayout(new GridLayout(2, 1)); psouth.add(p3); psouth.add(p1); // adding label and textfields to panel p2 p2.setLayout(new GridLayout(3, 1)); // setting line and titled border for panel p2 p2.setBorder(BorderFactory.createLineBorder(Color.red)); p2.setBorder(BorderFactory.createTitledBorder("Enter Your Details")); p2.add(lblname); p2.add(tf1); p2.add(lbladd); p2.add(tf2); // adding panel to container this.getContentPane().add(p2, "Center"); this.getContentPane().add(psouth, "South"); this.setSize(300, 300); this.setLocation(100, 200); this.show(); }
public void createColorPanel() { JPanel colorPanel = new JPanel(new GridLayout(0, 1)); int curRow = 0; for (int i = 0; i < colorString.length / 5; i++) { JPanel row = new JPanel(new GridLayout(1, 0, 2, 1)); row.setBorder(new EmptyBorder(2, 2, 2, 2)); for (int j = curRow; j < curRow + 5; j++) { final JLabel colorLabel = new JLabel(null, new ColoredIcon(color[j], 14, 14), JLabel.CENTER); colorLabel.setOpaque(true); final Border emb = BorderFactory.createEmptyBorder(2, 1, 2, 1); final Border lnb = BorderFactory.createLineBorder(Color.black); final Border cmb = BorderFactory.createCompoundBorder(lnb, emb); colorLabel.setBorder(emb); colorLabel.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { JButton btn = (JButton) getTarget(); Color selColor = ((ColoredIcon) colorLabel.getIcon()).getCurrentColor(); btn.setIcon(new ColoredIcon(selColor)); setVisible(false); btn.doClick(); oldLabel.setBackground(null); colorLabel.setBackground(new Color(150, 150, 200)); colorLabel.setBorder(emb); oldLabel = colorLabel; } public void mouseEntered(MouseEvent e) { colorLabel.setBorder(cmb); colorLabel.setBackground(new Color(150, 150, 200)); } public void mouseExited(MouseEvent e) { colorLabel.setBorder(emb); colorLabel.setBackground(null); } }); row.add(colorLabel); } colorPanel.add(row); curRow += row.getComponentCount(); // System.out.println(curRow); } add(colorPanel, BorderLayout.CENTER); // More Colors Button moreColors = new JButton(new ColorChooserAction((JButton) target)); moreColors.setText("More Colors..."); moreColors.setIcon(null); moreColors.setFont(new Font("Verdana", Font.PLAIN, 10)); // JPanel c = new JPanel(new FlowLayout(FlowLayout.CENTER)); c.add(moreColors); add(c, BorderLayout.SOUTH); }
/** * Gets the progress bar border. * * @return the progress bar border */ public static Border getProgressBarBorder() { if (progressBarBorder == null) { progressBarBorder = BorderFactory.createLineBorder( ColorHelper.darker(AbstractLookAndFeel.getBackgroundColor(), 30)); } return progressBarBorder; }
public RowPanel(String name) { super(); Border empty = BorderFactory.createEmptyBorder(10, 10, 10, 10); Border line = BorderFactory.createLineBorder(Color.GRAY); Border title = BorderFactory.createTitledBorder(line, name); Border compound = BorderFactory.createCompoundBorder(title, empty); setBorder(compound); setLayout(new RowLayout()); }
public ComboBoxDemo2() { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z", "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" }; currentPattern = patternExamples[0]; // Set up the UI for selecting a pattern. JLabel patternLabel1 = new JLabel("Enter the pattern string or"); JLabel patternLabel2 = new JLabel("select one from the list:"); JComboBox patternList = new JComboBox(patternExamples); patternList.setEditable(true); patternList.addActionListener(this); // Create the UI for displaying result. JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); // == LEFT result = new JLabel(" "); result.setForeground(Color.black); result.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(Color.black), BorderFactory.createEmptyBorder(5, 5, 5, 5))); // Lay out everything. JPanel patternPanel = new JPanel(); patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS)); patternPanel.add(patternLabel1); patternPanel.add(patternLabel2); patternList.setAlignmentX(Component.LEFT_ALIGNMENT); patternPanel.add(patternList); JPanel resultPanel = new JPanel(new GridLayout(0, 1)); resultPanel.add(resultLabel); resultPanel.add(result); patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT); resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT); add(patternPanel); add(Box.createRigidArea(new Dimension(0, 10))); add(resultPanel); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); reformat(); } // constructor
public PlayButton(String name) { super(name); myBorder = BorderFactory.createCompoundBorder( BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(Color.black), BorderFactory.createLineBorder(Color.blue)), BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(Color.cyan), BorderFactory.createLineBorder(Color.white))); addMouseListener( new MouseAdapter() { public void mouseEntered(MouseEvent e) { setBorder(myBorder); } public void mouseExited(MouseEvent e) { setBorder(null); } }); }
public static void main(String arg[]) { JFrame f = new JFrame("SimpleBorder"); Container content = f.getContentPane(); JButton b = new JButton(); b.setBorder(BorderFactory.createLineBorder(Color.blue, 10)); content.add(b); f.setSize(200, 150); f.show(); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
CGFrame() { pane.setBounds(20, 20, 200, 200); // 設定pane畫布的框線厚度為 4 像素 pane.setBorder(BorderFactory.createLineBorder(Color.blue, 4)); add(pane); for (int i = 0; i <= 4; i++) { btnCr[i] = new JButton(); btnCr[i].setBounds(21 + i * 42, 230, 30, 30); // 設定顏色按鈕目前全部呈浮凸狀 btnCr[i].setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); btnCr[i].setBackground(cr[i]); add(btnCr[i]); btnCr[i].addActionListener(this); } setTitle("點選顏色"); setLayout(null); setBounds(50, 50, 248, 310); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
public void init() { jf.setLayout(new GridLayout(2, 4)); // 使用静态工厂方法创建BevelBorder Border bb = BorderFactory.createBevelBorder( BevelBorder.RAISED, Color.RED, Color.GREEN, Color.BLUE, Color.GRAY); jf.add(getPanelWithBorder(bb, "BevelBorder")); // 使用静态工厂方法创建LineBorder Border lb = BorderFactory.createLineBorder(Color.ORANGE, 10); jf.add(getPanelWithBorder(lb, "LineBorder")); // 使用静态工厂方法创建EmptyBorder,EmptyBorder就是在组件四周留空 Border eb = BorderFactory.createEmptyBorder(20, 5, 10, 30); jf.add(getPanelWithBorder(eb, "EmptyBorder")); // 使用静态工厂方法创建EtchedBorder Border etb = BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.RED, Color.GREEN); jf.add(getPanelWithBorder(etb, "EtchedBorder")); // 直接创建TitledBorder,TitledBorder边框就是为原有的边框增加标题 TitledBorder tb = new TitledBorder( lb, "测试标题", TitledBorder.LEFT, TitledBorder.BOTTOM, new Font("StSong", Font.BOLD, 18), Color.BLUE); jf.add(getPanelWithBorder(tb, "TitledBorder")); // 直接创建MatteBorder,MatteBorder边框是EmptyBorder的子类, // 它可以指定留空区域的颜色或背景,此处是指定颜色 MatteBorder mb = new MatteBorder(20, 5, 10, 30, Color.GREEN); jf.add(getPanelWithBorder(mb, "MatteBorder")); // 直接创建CompoundBorder,CompoundBorder边框将两个边框组合成新边框 CompoundBorder cb = new CompoundBorder(new LineBorder(Color.RED, 8), tb); jf.add(getPanelWithBorder(cb, "CompoundBorder")); jf.pack(); jf.setVisible(true); }
void jbInit() throws Exception { titledBorder1 = new TitledBorder( BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "Assembler messages"); this.getContentPane().setLayout(borderLayout1); this.setIconifiable(true); this.setMaximizable(true); this.setResizable(true); this.setTitle("EDIT"); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); splitPane.setDividerLocation(470); sourceArea.setFont(new java.awt.Font("Monospaced", 0, 12)); controlPanel.setLayout(gridBagLayout1); controlPanel.setBorder(BorderFactory.createLoweredBevelBorder()); positionPanel.setLayout(gridBagLayout2); fileLabel.setText("Source file:"); fileText.setEditable(false); browseButton.setSelected(false); browseButton.setText("Browse ..."); assembleButton.setEnabled(false); assembleButton.setText("Assemble file"); saveButton.setEnabled(false); saveButton.setText("Save file"); lineLabel.setText("Line:"); lineText.setMinimumSize(new Dimension(50, 20)); lineText.setPreferredSize(new Dimension(50, 20)); lineText.setEditable(false); columnLabel.setText("Column:"); columnText.setMinimumSize(new Dimension(41, 20)); columnText.setPreferredSize(new Dimension(41, 20)); columnText.setEditable(false); columnText.setText(""); messageScrollPane.setBorder(titledBorder1); messageScrollPane.setMinimumSize(new Dimension(33, 61)); messageScrollPane.setPreferredSize(new Dimension(60, 90)); optionsButton.setEnabled(false); optionsButton.setText("Assembler options ..."); messageScrollPane.getViewport().add(messageList, null); messageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.getContentPane().add(splitPane, BorderLayout.CENTER); splitPane.add(textScrollPane, JSplitPane.TOP); splitPane.add(controlPanel, JSplitPane.BOTTOM); textScrollPane.getViewport().add(sourceArea, null); controlPanel.add( fileLabel, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( fileText, new GridBagConstraints( 1, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( browseButton, new GridBagConstraints( 4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0)); controlPanel.add( optionsButton, new GridBagConstraints( 2, 1, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( assembleButton, new GridBagConstraints( 3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( saveButton, new GridBagConstraints( 4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0)); controlPanel.add( positionPanel, new GridBagConstraints( 0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); positionPanel.add( lineLabel, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); positionPanel.add( lineText, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0)); positionPanel.add( columnLabel, new GridBagConstraints( 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); positionPanel.add( columnText, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0)); controlPanel.add( messageScrollPane, new GridBagConstraints( 0, 2, 5, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); }
public InterpreterFrame() { super("Simple Lisp Interpreter"); // Create the menu menubar = buildMenuBar(); setJMenuBar(menubar); // Create the toolbar toolbar = buildToolBar(); // disable cut and copy actions cutAction.setEnabled(false); copyAction.setEnabled(false); // Setup text area for editing source code // and setup document listener so interpreter // is notified when current file modified and // when the cursor is moved. textView = buildEditor(); textView.getDocument().addDocumentListener(this); textView.addCaretListener(this); // set default key bindings bindKeyToCommand("ctrl C", "(buffer-copy)"); bindKeyToCommand("ctrl X", "(buffer-cut)"); bindKeyToCommand("ctrl V", "(buffer-paste)"); bindKeyToCommand("ctrl E", "(buffer-eval)"); bindKeyToCommand("ctrl O", "(file-open)"); bindKeyToCommand("ctrl S", "(file-save)"); bindKeyToCommand("ctrl Q", "(exit)"); // Give text view scrolling capability Border border = BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(3, 3, 3, 3), BorderFactory.createLineBorder(Color.gray)); JScrollPane topSplit = addScrollers(textView); topSplit.setBorder(border); // Create tabbed pane for console/problems consoleView = makeConsoleArea(10, 50, true); problemsView = makeConsoleArea(10, 50, false); tabbedPane = buildProblemsConsole(); // Plug the editor and problems/console together // using a split pane. This allows one to change // their relative size using the split-bar in // between them. splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topSplit, tabbedPane); // Create status bar statusView = new JLabel(" Status"); lineNumberView = new JLabel("0:0"); statusbar = buildStatusBar(); // Now, create the outer panel which holds // everything together outerpanel = new JPanel(); outerpanel.setLayout(new BorderLayout()); outerpanel.add(toolbar, BorderLayout.PAGE_START); outerpanel.add(splitPane, BorderLayout.CENTER); outerpanel.add(statusbar, BorderLayout.SOUTH); getContentPane().add(outerpanel); // tell frame to fire a WindowsListener event // but not to close when "x" button clicked. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(this); // set minimised icon to use setIconImage(makeImageIcon("spi.png").getImage()); // setup additional internal functions InternalFunctions.setup_internals(interpreter, this); // set default window size Component top = splitPane.getTopComponent(); Component bottom = splitPane.getBottomComponent(); top.setPreferredSize(new Dimension(100, 400)); bottom.setPreferredSize(new Dimension(100, 200)); pack(); // load + run user configuration file (if there is one) String homedir = System.getProperty("user.home"); try { interpreter.load(homedir + "/.simplelisp"); } catch (FileNotFoundException e) { // do nothing if file does not exist! System.out.println("Didn't find \"" + homedir + "/.simplelisp\""); } textView.grabFocus(); setVisible(true); // redirect all I/O to problems/console redirectIO(); // start highlighter thread highlighter = new DisplayThread(250); highlighter.setDaemon(true); highlighter.start(); }
public AboutDialog(JConsole jConsole) { super(jConsole, Resources.getText("Help.AboutDialog.title"), false); setAccessibleDescription(this, getText("Help.AboutDialog.accessibleDescription")); setDefaultCloseOperation(HIDE_ON_CLOSE); setResizable(false); JComponent cp = (JComponent) getContentPane(); createActions(); JLabel mastheadLabel = new JLabel(mastheadIcon); setAccessibleName(mastheadLabel, getText("Help.AboutDialog.masthead.accessibleName")); JPanel mainPanel = new TPanel(0, 0); mainPanel.add(mastheadLabel, NORTH); String jConsoleVersion = Version.getVersion(); String vmName = System.getProperty("java.vm.name"); String vmVersion = System.getProperty("java.vm.version"); String urlStr = getText("Help.AboutDialog.userGuideLink.url"); if (isBrowseSupported()) { urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>"; } JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10)); infoAndLogoPanel.setBackground(bgColor); String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF); JEditorPane helpLink = new JEditorPane( "text/html", "<html><font color=#" + colorStr + ">" + getText("Help.AboutDialog.jConsoleVersion", jConsoleVersion) + "<p>" + getText("Help.AboutDialog.javaVersion", (vmName + ", " + vmVersion)) + "<p>" + getText("Help.AboutDialog.userGuideLink", urlStr) + "</html>"); helpLink.setOpaque(false); helpLink.setEditable(false); helpLink.setForeground(textColor); mainPanel.setBorder(BorderFactory.createLineBorder(borderColor)); infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); helpLink.addHyperlinkListener( new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { browse(e.getDescription()); } } }); infoAndLogoPanel.add(helpLink, NORTH); ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource("resources/brandlogo.png")); JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING); JButton closeButton = new JButton(closeAction); JPanel bottomPanel = new TPanel(0, 0); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING)); buttonPanel.setOpaque(false); mainPanel.add(infoAndLogoPanel, CENTER); cp.add(bottomPanel, SOUTH); infoAndLogoPanel.add(brandLogo, SOUTH); buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12)); buttonPanel.add(closeButton); bottomPanel.add(buttonPanel, NORTH); statusBar = new JLabel(" "); bottomPanel.add(statusBar, SOUTH); cp.add(mainPanel, NORTH); pack(); setLocationRelativeTo(jConsole); Utilities.updateTransparency(this); }
/** * Create me * * @param persistenceManager A reference to the persistence manager in case we need it * @param label The label to use in the dialog title */ public LoadBundleDialog(IdvPersistenceManager persistenceManager, String label) { dialogTitle = label; label = null; this.persistenceManager = persistenceManager; msgLabel1 = new JLabel(" "); msgLabel1.setMinimumSize(new Dimension(250, 20)); msgLabel1.setPreferredSize(new Dimension(250, 20)); msgLabel2 = new JLabel(" "); msgLabel2.setMinimumSize(new Dimension(250, 20)); msgLabel2.setPreferredSize(new Dimension(250, 20)); progressBar = new RovingProgress(); progressBar.start(); progressBar.setBorder(BorderFactory.createLineBorder(Color.gray)); JLabel waitLbl = new JLabel(IdvWindow.getWaitIcon()); ActionListener buttonListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { removeItems = true; // removeItems = ae.getActionCommand().equals(CMD_CANCELANDREMOVE); okToRun = false; setMessage("Cancelling load. Please wait..."); Misc.runInABit( 2000, new Runnable() { public void run() { dispose(); } }); } }; // String[] cmds = { CMD_CANCELANDREMOVE, GuiUtils.CMD_CANCEL }; String[] cmds = {GuiUtils.CMD_CANCEL}; // String[] tts = { "Press to cancel and remove any loaded items", // "Press to cancel" }; String[] tts = {"Press to cancel and remove loaded items"}; JPanel buttonPanel = GuiUtils.makeButtons(buttonListener, cmds, cmds, tts, null); GuiUtils.tmpInsets = GuiUtils.INSETS_2; JComponent labelComp = GuiUtils.doLayout( new Component[] { new JLabel("Status:"), msgLabel1, waitLbl, GuiUtils.filler(), msgLabel2, GuiUtils.filler() }, 3, GuiUtils.WT_NYN, GuiUtils.WT_N); contents = GuiUtils.inset(labelComp, 5); if (label != null) { contents = GuiUtils.topCenter(GuiUtils.cLabel("Loading: " + label), contents); } // contents = GuiUtils.vbox(contents, // GuiUtils.inset(progressBar, 5), // buttonPanel); contents = GuiUtils.vbox(contents, buttonPanel); }