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:MyLabel.java
public static void main(String[] args) { String lyrics = "<html>Line<br>line<br>line</html>"; JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(10, 10)); JLabel label = new JLabel(lyrics); label.setFont(new Font("Georgia", Font.PLAIN, 14)); label.setForeground(new Color(50, 50, 25)); panel.add(label, BorderLayout.CENTER); panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JFrame f = new JFrame(); f.add(panel);// w w w . ja va2 s .c o m f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:FtfInputVerifier.java
public static void main(String argv[]) { java.net.URL u = null;/* w ww . j ava 2s.c o m*/ try { u = new java.net.URL("http://www.ora.com/"); } catch (java.net.MalformedURLException ignored) { } // create two identical JFormattedTextFields JFormattedTextField ftf1 = new JFormattedTextField(u); JFormattedTextField ftf2 = new JFormattedTextField(u); // and set an InputVerifier on one of them ftf2.setInputVerifier(new InputVerifier() { public boolean verify(JComponent input) { if (!(input instanceof JFormattedTextField)) return true; // give up focus return ((JFormattedTextField) input).isEditValid(); } }); JPanel p = new JPanel(new java.awt.GridLayout(0, 2, 3, 8)); p.add(new JLabel("plain JFormattedTextField:", JLabel.RIGHT)); p.add(ftf1); p.add(new JLabel("FTF with InputVerifier:", JLabel.RIGHT)); p.add(ftf2); p.add(new JLabel("plain JTextField:", JLabel.RIGHT)); p.add(new JTextField(u.toString())); p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); JFrame f = new JFrame("FtfInputVerifier"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JLabel("Try to delete the colon in each field.", JLabel.CENTER), java.awt.BorderLayout.NORTH); f.getContentPane().add(p, java.awt.BorderLayout.CENTER); f.pack(); f.setVisible(true); }
From source file:moviedatas.MovieDatas.java
public static void main(String[] args) { FilterController fpc = new FilterController(); SortController spc = new SortController(); //1. Create the frame. JFrame frame = new JFrame("Movies Open Datas by Harp-e"); frame.setPreferredSize(new Dimension(1280, 800)); //2. Optional: What happens when the frame closes? frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MovieListView movieListView = new MovieListView(); JPanel movieListPanel = movieListView.createViewPanel(); TitledBorder moviesTitle;/*from ww w . jav a2 s. c o m*/ moviesTitle = BorderFactory.createTitledBorder("Movies"); movieListPanel.setBorder(moviesTitle); //3. Create components and put them in the frame. //---------------------------------------------------------------------- // Sort & Filter panel (right) //---------------------------------------------------------------------- SortPanelView sortFilterView = new SortPanelView(); FilterPanelView filterPanelView = new FilterPanelView(); JPanel sortPanel = sortFilterView.createSortPanel(); JPanel filterPanel = filterPanelView.createFilterPanel(); JPanel sortFilterPanel = new JPanel(); sortFilterPanel.setLayout(new BoxLayout(sortFilterPanel, BoxLayout.PAGE_AXIS)); sortFilterPanel.add(sortPanel); sortFilterPanel.add(filterPanel); frame.getContentPane().add(sortFilterPanel, BorderLayout.WEST); //---------------------------------------------------------------------- // Movie Info Panel (left) //---------------------------------------------------------------------- MovieInfoController movieInfoController = new MovieInfoController(); JPanel movieInfoView = movieInfoController.initView(); TitledBorder infoTitle; infoTitle = BorderFactory.createTitledBorder("Informations"); movieInfoView.setBorder(infoTitle); //---------------------------------------------------------------------- // Movie List Panel (middle) //---------------------------------------------------------------------- JPanel listPanel = new JPanel(); listPanel.setLayout(new BorderLayout()); listPanel.setPreferredSize(new Dimension(1280, 400)); listPanel.add(sortFilterPanel, BorderLayout.WEST); listPanel.add(movieInfoView, BorderLayout.EAST); listPanel.add(movieListPanel, BorderLayout.CENTER); frame.getContentPane().add(listPanel, BorderLayout.NORTH); //---------------------------------------------------------------------- // Charts Panel (bottom) //---------------------------------------------------------------------- JPanel chartPanel = new JPanel(); // Spider chart Panel //______________________________________________________________________ // Create the panel JPanel spiderPanel = new JPanel(); // Create the view SpiderChartView spiderChartView = new SpiderChartView(); // Create a tilte TitledBorder spiderTitle; // Put a border around the title spiderTitle = BorderFactory.createTitledBorder("Spider chart"); // Put the border on the panel spiderPanel.setBorder(spiderTitle); // Put the view on the panel spiderPanel.add(spiderChartView.initView()); // Put the spider panel on the global panel chartPanel.add(spiderPanel); //______________________________________________________________________ // Bar chart Panel //______________________________________________________________________ JPanel barPanel = new JPanel(); BarChartView barChartView = new BarChartView(); TitledBorder barTitle; barTitle = BorderFactory.createTitledBorder("Bar chart"); barPanel.setBorder(barTitle); barPanel.add(barChartView.initView()); chartPanel.add(barPanel); //______________________________________________________________________ // Global chart Panel //______________________________________________________________________ JPanel globalChartPanel = new JPanel(); GlobalChart globalChartView = new GlobalChart(); TitledBorder globalTitle; globalTitle = BorderFactory.createTitledBorder("Global chart"); globalChartPanel.setBorder(globalTitle); globalChartPanel.add(globalChartView.initView()); chartPanel.add(globalChartPanel); //______________________________________________________________________ frame.getContentPane().add(chartPanel, BorderLayout.CENTER); //---------------------------------------------------------------------- //4. Size the frame. frame.pack(); //5. Show it. frame.setVisible(true); //ArrayList<Movie> movies = new ArrayList<>(); //FilterController.filter(10,SortController.byTitle(movies)); }
From source file:ca.sqlpower.wabit.swingui.enterprise.UserPanel.java
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { WabitWorkspace p = new WabitWorkspace(); p.setUUID("system"); // Add data sources to workspace DataSourceCollection<SPDataSource> plini = new PlDotIni(); plini.read(new File(System.getProperty("user.home"), "pl.ini")); List<SPDataSource> dataSources = plini.getConnections(); for (int i = 0; i < 10 && i < dataSources.size(); i++) { p.addDataSource(new WabitDataSource(dataSources.get(i))); }/*from w ww. j av a 2 s. com*/ // Add layouts to workspace Report layout = new Report("Example Layout"); p.addReport(layout); Page page = layout.getPage(); page.addContentBox(new ContentBox()); page.addGuide(new Guide(Axis.HORIZONTAL, 123)); page.addContentBox(new ContentBox()); // dd a report task ReportTask task = new ReportTask(); task.setReport(layout); p.addReportTask(task); User user = new User("admin", "admin"); user.setParent(p); Group group = new Group("Admins"); group.setParent(p); group.addMember(new GroupMember(user)); Group group2 = new Group("Other Group"); group2.setParent(p); p.addUser(user); p.addGroup(group); p.addGroup(group2); UserPanel panel = new UserPanel(user); UserPanel panel2 = new UserPanel(user); JFrame f = new JFrame("TEST PANEL"); JPanel outerPanel = new JPanel(new BorderLayout()); outerPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE)); outerPanel.add(panel.getPanel(), BorderLayout.CENTER); f.setContentPane(outerPanel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); JFrame f2 = new JFrame("TEST PANEL"); JPanel outerPanel2 = new JPanel(new BorderLayout()); outerPanel2.setBorder(BorderFactory.createLineBorder(Color.BLUE)); outerPanel2.add(panel2.getPanel(), BorderLayout.CENTER); f2.setContentPane(outerPanel2); f2.pack(); f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f2.setVisible(true); } catch (Exception ex) { throw new RuntimeException(ex); } } }); }
From source file:GlueSample.java
public static void main(String args[]) { Box horizontalBox;// w w w. ja v a 2 s . c o m JPanel panel; JFrame frame = new JFrame("Horizontal Glue"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(0, 1)); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning Glue")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Middle")); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("2 Middle Glues")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); horizontalBox.add(Box.createGlue()); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning/End Glues")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); horizontalBox.add(Box.createGlue()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("End Glue")); contentPane.add(panel); frame.setSize(300, 300); frame.setVisible(true); }
From source file:StrutSample.java
public static void main(String args[]) { Box horizontalBox;/*w w w .j a va 2 s . c o m*/ JPanel panel; JFrame frame = new JFrame("Horizontal Strut"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(0, 1)); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createHorizontalStrut(10)); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning Strut")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(Box.createHorizontalStrut(10)); horizontalBox.add(new JButton("Middle")); horizontalBox.add(Box.createHorizontalStrut(25)); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("2 Middle Struts")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createHorizontalStrut(25)); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); horizontalBox.add(Box.createHorizontalStrut(10)); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning/End Struts")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); horizontalBox.add(Box.createHorizontalStrut(10)); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("End Strut")); contentPane.add(panel); frame.setSize(300, 300); frame.setVisible(true); }
From source file:DateTimeEditor.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0);//from ww w . j a v a2 s.co m } }); JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(new EmptyBorder(5, 5, 5, 5)); frame.setContentPane(panel); final DateTimeEditor field = new DateTimeEditor(DateTimeEditor.DATETIME, DateFormat.FULL); panel.add(field, "North"); JPanel buttonBox = new JPanel(new GridLayout(2, 2)); JButton showDateButton = new JButton("Show Date"); buttonBox.add(showDateButton); final JComboBox timeDateChoice = new JComboBox(); timeDateChoice.addItem("Time"); timeDateChoice.addItem("Date"); timeDateChoice.addItem("Date/Time"); timeDateChoice.setSelectedIndex(2); timeDateChoice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { field.setTimeOrDateType(timeDateChoice.getSelectedIndex()); } }); buttonBox.add(timeDateChoice); JButton toggleButton = new JButton("Toggle Enable"); buttonBox.add(toggleButton); showDateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println(field.getDate()); } }); toggleButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { field.setEnabled(!field.isEnabled()); } }); panel.add(buttonBox, "South"); final JComboBox lengthStyleChoice = new JComboBox(); lengthStyleChoice.addItem("Full"); lengthStyleChoice.addItem("Long"); lengthStyleChoice.addItem("Medium"); lengthStyleChoice.addItem("Short"); lengthStyleChoice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { field.setLengthStyle(lengthStyleChoice.getSelectedIndex()); } }); buttonBox.add(lengthStyleChoice); frame.pack(); Dimension dim = frame.getToolkit().getScreenSize(); frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2); frame.show(); }
From source file:com.limegroup.gnutella.gui.notify.AnimatedWindow.java
public static void main(String[] args) { JPanel content = new JPanel(new BorderLayout()); content.setBorder(BorderFactory.createLineBorder(Color.black, 2)); JLabel label = new JLabel("Hello World"); label.setIcon(UIManager.getIcon("FileView.computerIcon")); label.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); content.add(label, BorderLayout.CENTER); final AnimatedWindow window = new AnimatedWindow(null); window.setFinalLocation(new Point(200, 200)); window.setContentPane(content);/*from w ww. j a va2 s . co m*/ JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10)); JButton button = new JButton("Bottom -> Top"); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setMode(AnimationMode.BOTTOM_TO_TOP); if (!window.isVisible() || window.isHideAnimationInProgress()) { window.doShow(); } else { window.doHide(); } } }); button = new JButton("Top -> Bottom"); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setMode(AnimationMode.TOP_TO_BOTTOM); if (!window.isVisible() || window.isHideAnimationInProgress()) { window.doShow(); } else { window.doHide(); } } }); button = new JButton("Fade"); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setMode(AnimationMode.FADE); if (!window.isVisible() || window.isHideAnimationInProgress()) { window.doShow(); } else { window.doHide(); } } }); JFrame app = new JFrame("AnimatedWindow Demo"); app.setContentPane(buttonPanel); app.pack(); app.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); app.setVisible(true); }
From source file:ImageBorderHack.java
public static void main(String[] args) { JFrame frame = new JFrame("Hack #59: Image Border"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JButton button = new JButton("Image Border Test"); panel.add(button);/* ww w. j a va2 s . co m*/ ImageBorder image_border = new ImageBorder(new ImageIcon("upperLeft.png").getImage(), new ImageIcon("upper.png").getImage(), new ImageIcon("upperRight.png").getImage(), new ImageIcon("leftCenter.png").getImage(), new ImageIcon("rightCenter.png").getImage(), new ImageIcon("bottomLeft.png").getImage(), new ImageIcon("bottomCenter.png").getImage(), new ImageIcon("bottomRight.png").getImage()); panel.setBorder(image_border); frame.getContentPane().add(panel); frame.pack(); // frame.setSize(200,200); frame.setVisible(true); }
From source file:lu.lippmann.cdb.graph.GraphViewImpl.java
/** * /*from w ww .j a v a2s.c om*/ * @param args * @throws UnsupportedLookAndFeelException */ public static final void main(String[] args) throws UnsupportedLookAndFeelException { LookAndFeelUtil.init(); final JXFrame f = new JXFrame(); f.setDefaultCloseOperation(JXFrame.EXIT_ON_CLOSE); final GraphView view = new GraphViewImpl(new EventPublisherBushImpl(), new CommandDispatcherBushImpl()); view.setViewMode(ViewMode.Add); view.init(); final int panelWidth = 800; final int panelHeigth = 800; final VisualizationViewer<CNode, CEdge> vv = view.getVisualisationViewer(); vv.setPreferredSize(new Dimension(panelWidth, panelHeigth)); f.setSize(new Dimension(panelWidth, panelHeigth)); LogoHelper.setLogo(f); f.setTitle("GraphView test"); //f.setLayout(new BorderLayout()); final GraphWithOperations gwo = new GraphWithOperations(); final CGraph cg = new CGraph(); final FRLayout<CNode, CEdge> layout = new FRLayout<CNode, CEdge>(gwo); cg.setInternalLayout(layout); view.setCGraph(cg); /* final JRadioButton hyperView = new JRadioButton("Hyperbolic View"); hyperView.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent e) { ((GraphViewImpl)view).lensSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); */ CadralGraphMouse gm = ((CadralGraphMouse) view.getVisualisationViewer().getGraphMouse()); gm.setClickedGraph(gwo); final GraphWithOperations g = (GraphWithOperations) view.getVisualisationViewer().getModel() .getGraphLayout().getGraph(); final CNode n1 = new CNode("N1"); g.addVertex(n1); layout.setLocation(n1, new Point2D.Double(400, 400)); /* final CNode n2 = new CNode("N2"); g.addVertex(n2); final CNode n3 = new CNode("N3"); g.addVertex(n3); g.addEdge(new CEdge("E1"),n1,n2,EdgeType.DIRECTED); layout.setLocation(n1,new Point2D.Double(250,250)); layout.setLocation(n3,new Point2D.Double(100,250)); */ final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel hyperControls = new JPanel(new GridLayout(3, 2)); hyperControls.setBorder(BorderFactory.createTitledBorder("Examiner Lens")); zoomControls.add(plus); zoomControls.add(minus); JPanel modeControls = new JPanel(new BorderLayout()); modeControls.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modeControls.add(gm.getModeComboBox()); //hyperControls.add(hyperView); Container content = f.getContentPane(); controls.add(zoomControls); // controls.add(hyperControls); controls.add(modeControls); content.add(controls, BorderLayout.SOUTH); //GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(view.asComponent()); //f.add(view.asComponent()); f.setVisible(true); f.pack(); }