List of usage examples for javax.swing JPanel setBorder
@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.") public void setBorder(Border border)
From source file:CommonLayouts.java
public CommonLayouts() { super("Common Layout Managers"); setSize(500, 380);// w w w. j a va 2 s . c o m JPanel desktop = new JPanel(); getContentPane().add(desktop); JPanel fr1 = new JPanel(); fr1.setBorder(new TitledBorder("FlowLayout")); fr1.setLayout(new FlowLayout()); fr1.add(new JButton("1")); fr1.add(new JButton("2")); fr1.add(new JButton("3")); fr1.add(new JButton("4")); desktop.add(fr1, 0); JPanel fr2 = new JPanel(); fr2.setBorder(new TitledBorder("GridLayout")); fr2.setLayout(new GridLayout(2, 2)); fr2.add(new JButton("1")); fr2.add(new JButton("2")); fr2.add(new JButton("3")); fr2.add(new JButton("4")); desktop.add(fr2, 0); JPanel fr3 = new JPanel(); fr3.setBorder(new TitledBorder("BorderLayout")); fr3.add(new JButton("1"), BorderLayout.NORTH); fr3.add(new JButton("2"), BorderLayout.EAST); fr3.add(new JButton("3"), BorderLayout.SOUTH); fr3.add(new JButton("4"), BorderLayout.WEST); desktop.add(fr3, 0); JPanel fr4 = new JPanel(); fr4.setBorder(new TitledBorder("BoxLayout - X")); fr4.setLayout(new BoxLayout(fr4, BoxLayout.X_AXIS)); fr4.add(new JButton("1")); fr4.add(Box.createHorizontalStrut(12)); fr4.add(new JButton("2")); fr4.add(Box.createGlue()); fr4.add(new JButton("3")); fr4.add(Box.createHorizontalGlue()); fr4.add(new JButton("4")); desktop.add(fr4, 0); JPanel fr5 = new JPanel(); fr5.setBorder(new TitledBorder("BoxLayout - Y")); fr5.setLayout(new BoxLayout(fr5, BoxLayout.Y_AXIS)); fr5.add(new JButton("1")); fr5.add(Box.createVerticalStrut(10)); fr5.add(new JButton("2")); fr5.add(Box.createGlue()); fr5.add(new JButton("3")); fr5.add(Box.createVerticalGlue()); fr5.add(new JButton("4")); desktop.add(fr5, 0); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:Main.java
public Main() { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); JPanel panel1 = new JPanel(); Border eBorder = BorderFactory.createEtchedBorder(); panel1.setBorder(BorderFactory.createTitledBorder(eBorder, "70pct")); gbc.gridx = gbc.gridy = 0;/*from w w w. ja v a2 s . c om*/ gbc.gridwidth = gbc.gridheight = 1; gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.weightx = gbc.weighty = 70; add(panel1, gbc); JPanel panel2 = new JPanel(); panel2.setBorder(BorderFactory.createTitledBorder(eBorder, "30pct")); gbc.gridy = 1; gbc.weightx = gbc.weighty = 30; gbc.insets = new Insets(2, 2, 2, 2); add(panel2, gbc); JPanel panel3 = new JPanel(); panel3.setBorder(BorderFactory.createTitledBorder(eBorder, "20pct")); gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 2; gbc.weightx = 20; gbc.insets = new Insets(2, 2, 2, 2); add(panel3, gbc); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true); }
From source file:AnotherBorderTest.java
public AnotherBorderTest() { setTitle("Border Test"); setSize(450, 450);/*w w w . jav a2 s .c o m*/ JPanel content = (JPanel) getContentPane(); content.setLayout(new GridLayout(6, 2, 3, 3)); JPanel p = new JPanel(); p.setBorder(new BevelBorder(BevelBorder.RAISED)); p.add(new JLabel("RAISED BevelBorder")); content.add(p); p = new JPanel(); p.setBorder(new BevelBorder(BevelBorder.LOWERED)); p.add(new JLabel("LOWERED BevelBorder")); content.add(p); p = new JPanel(); p.setBorder(new LineBorder(Color.black, 5)); p.add(new JLabel("Black LineBorder, thickness = 5")); content.add(p); p = new JPanel(); p.setBorder(new EmptyBorder(10, 10, 10, 10)); p.add(new JLabel("EmptyBorder with thickness of 10")); content.add(p); p = new JPanel(); p.setBorder(new EtchedBorder(EtchedBorder.RAISED)); p.add(new JLabel("RAISED EtchedBorder")); content.add(p); p = new JPanel(); p.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); p.add(new JLabel("LOWERED EtchedBorder")); content.add(p); p = new JPanel(); p.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED)); p.add(new JLabel("RAISED SoftBevelBorder")); content.add(p); p = new JPanel(); p.setBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED)); p.add(new JLabel("LOWERED SoftBevelBorder")); content.add(p); p = new JPanel(); p.setBorder(new MatteBorder(new ImageIcon("BALL.GIF"))); p.add(new JLabel("MatteBorder")); content.add(p); p = new JPanel(); p.setBorder(new TitledBorder(new MatteBorder(new ImageIcon("java2sLogo.gif")), "Title String")); p.add(new JLabel("TitledBorder using MatteBorder")); content.add(p); p = new JPanel(); p.setBorder(new TitledBorder(new LineBorder(Color.black, 5), "Title String")); p.add(new JLabel("TitledBorder using LineBorder")); content.add(p); p = new JPanel(); p.setBorder(new TitledBorder(new EmptyBorder(10, 10, 10, 10), "Title String")); p.add(new JLabel("TitledBorder using EmptyBorder")); content.add(p); setVisible(true); }
From source file:Main.java
public Main() { JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5)); ImageIcon icon = new ImageIcon(Toolkit.getDefaultToolkit().getImage("matte.gif")); simplePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), BorderFactory.createMatteBorder(-1, -1, -1, -1, icon))); simplePanel.add(new JLabel("Examples"), JLabel.CENTER); add(simplePanel);/*from ww w.jav a2 s.c om*/ }
From source file:MonthPanel.java
protected JPanel createDaysGUI() { JPanel dayPanel = new JPanel(true); dayPanel.setLayout(new GridLayout(0, dayNames.length)); Calendar today = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.DAY_OF_MONTH, 1); Calendar iterator = (Calendar) calendar.clone(); iterator.add(Calendar.DAY_OF_MONTH, -(iterator.get(Calendar.DAY_OF_WEEK) - 1)); Calendar maximum = (Calendar) calendar.clone(); maximum.add(Calendar.MONTH, +1); for (int i = 0; i < dayNames.length; i++) { JPanel dPanel = new JPanel(true); dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); JLabel dLabel = new JLabel(dayNames[i]); dPanel.add(dLabel);/*from w w w .j a v a2s.co m*/ dayPanel.add(dPanel); } int count = 0; int limit = dayNames.length * 6; while (iterator.getTimeInMillis() < maximum.getTimeInMillis()) { int lMonth = iterator.get(Calendar.MONTH); int lYear = iterator.get(Calendar.YEAR); JPanel dPanel = new JPanel(true); dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); JLabel dayLabel = new JLabel(); if ((lMonth == month) && (lYear == year)) { int lDay = iterator.get(Calendar.DAY_OF_MONTH); dayLabel.setText(Integer.toString(lDay)); } dPanel.add(dayLabel); dayPanel.add(dPanel); iterator.add(Calendar.DAY_OF_YEAR, +1); count++; } for (int i = count; i < limit; i++) { JPanel dPanel = new JPanel(true); dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); dPanel.add(new JLabel()); dayPanel.add(dPanel); } return dayPanel; }
From source file:SimpleFTF.java
public SimpleFTF() { JFormattedTextField ftf[] = new JFormattedTextField[7]; String des[] = new String[ftf.length]; // description of each field des[0] = "Date"; ftf[0] = new JFormattedTextField(new java.util.Date()); des[1] = "Integer"; ftf[1] = new JFormattedTextField(new Integer(90032221)); des[2] = "Float"; ftf[2] = new JFormattedTextField(new Float(3.14)); des[3] = "Float work-around"; // manually specify a NumberFormat ftf[3] = new JFormattedTextField(java.text.NumberFormat.getInstance()); ftf[3].setValue(new Float(3.14)); des[4] = "currency"; ftf[4] = new JFormattedTextField(java.text.NumberFormat.getCurrencyInstance()); ftf[4].setValue(new Float(5.99)); des[5] = "percent"; ftf[5] = new JFormattedTextField(java.text.NumberFormat.getPercentInstance()); ftf[5].setValue(new Float(0.33)); des[6] = "java.net.URL"; // works via 1-arg String constructor and // toString() java.net.URL u = null;/* w ww. ja va2s. c om*/ try { u = new java.net.URL("http://www.ora.com/"); } catch (java.net.MalformedURLException ignored) { } ftf[6] = new JFormattedTextField(u); ftf[6].setColumns(24); // add each ftf[] to a BoxLayout setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); for (int j = 0; j < ftf.length; j += 1) { JPanel borderPanel = new JPanel(new java.awt.BorderLayout()); borderPanel.setBorder(new javax.swing.border.TitledBorder(des[j])); borderPanel.add(ftf[j], java.awt.BorderLayout.CENTER); add(borderPanel); } }
From source file:net.sf.taverna.raven.plugins.ui.CheckForUpdatesDialog.java
private void initComponents() { // Base font for all components on the form Font baseFont = new JLabel("base font").getFont().deriveFont(11f); // Message saying that updates are available JPanel messagePanel = new JPanel(new BorderLayout()); messagePanel.setBorder( new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder(EtchedBorder.LOWERED))); JLabel message = new JLabel( "<html><body>Updates are available for some Taverna components. To review and <br>install them go to 'Updates and plugins' in the 'Advanced' menu.</body><html>"); message.setFont(baseFont.deriveFont(12f)); message.setBorder(new EmptyBorder(5, 5, 5, 5)); message.setIcon(UpdatesAvailableIcon.updateIcon); messagePanel.add(message, BorderLayout.CENTER); // Buttons//from ww w . j a v a2 s . c o m JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton okButton = new JButton("OK"); // we'll check for updates again in 2 weeks okButton.setFont(baseFont); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okPressed(); } }); buttonsPanel.add(okButton); getContentPane().setLayout(new BorderLayout()); getContentPane().add(messagePanel, BorderLayout.CENTER); getContentPane().add(buttonsPanel, BorderLayout.SOUTH); pack(); setResizable(false); // Center the dialog on the screen (we do not have the parent) Dimension dimension = getToolkit().getScreenSize(); Rectangle abounds = getBounds(); setLocation((dimension.width - abounds.width) / 2, (dimension.height - abounds.height) / 2); setSize(getPreferredSize()); }
From source file:GetApplets.java
private void createGUI() { JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10))); setContentPane(contentPane);/*from ww w . j a v a 2 s . c o m*/ JButton b = new JButton("Click to call getApplets()"); b.addActionListener(this); add(b, BorderLayout.PAGE_START); textArea = new JTextArea(5, 40); textArea.setEditable(false); JScrollPane scroller = new JScrollPane(textArea); add(scroller, BorderLayout.CENTER); }
From source file:my.jabbr.app.ftpclient.ui.install.ProductLicenseInstallationPanel.java
private JPanel createTransparentFillerPanel() { JPanel panel = new JPanel(); panel.setSize(645, 50);//from www. java 2 s . c om panel.setOpaque(false); panel.setBorder(null); return panel; }
From source file:MainClass.java
public JPanel createNested(boolean opaque) { JPanel outer = new JPanel(new FlowLayout()); JPanel inner = new JPanel(new FlowLayout()); outer.setBackground(Color.white); inner.setBackground(Color.black); inner.setOpaque(opaque);//from w ww .jav a2 s. c om inner.setBorder(BorderFactory.createLineBorder(Color.gray)); inner.add(new JButton("Button")); outer.add(inner); return outer; }