List of usage examples for javax.swing BorderFactory createEmptyBorder
public static Border createEmptyBorder(int top, int left, int bottom, int right)
From source file:SimpleDateFormatDemo.java
public SimpleDateFormatDemo() { today = new Date(); availableLocales = new LocaleGroup(); 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:"); patternLabel1.setAlignmentX(Component.LEFT_ALIGNMENT); patternLabel2.setAlignmentX(Component.LEFT_ALIGNMENT); JComboBox patternList = new JComboBox(patternExamples); patternList.setSelectedIndex(0);/*w ww .ja v a 2 s.c om*/ patternList.setEditable(true); patternList.setAlignmentX(Component.LEFT_ALIGNMENT); PatternListener patternListener = new PatternListener(); patternList.addActionListener(patternListener); // Set up the UI for selecting a locale. JLabel localeLabel = new JLabel("Select a Locale from the list:"); localeLabel.setAlignmentX(Component.LEFT_ALIGNMENT); JComboBox localeList = new JComboBox(availableLocales.getStrings()); localeList.setSelectedIndex(0); localeList.setAlignmentX(Component.LEFT_ALIGNMENT); LocaleListener localeListener = new LocaleListener(); localeList.addActionListener(localeListener); // Create the UI for displaying result JLabel resultLabel = new JLabel("Current Date and Time", JLabel.LEFT); resultLabel.setAlignmentX(Component.LEFT_ALIGNMENT); result = new JLabel(" "); result.setForeground(Color.black); result.setAlignmentX(Component.LEFT_ALIGNMENT); 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.Y_AXIS)); patternPanel.add(patternLabel1); patternPanel.add(patternLabel2); patternPanel.add(patternList); JPanel localePanel = new JPanel(); localePanel.setLayout(new BoxLayout(localePanel, BoxLayout.Y_AXIS)); localePanel.add(localeLabel); localePanel.add(localeList); JPanel resultPanel = new JPanel(); resultPanel.setLayout(new GridLayout(0, 1)); resultPanel.add(resultLabel); resultPanel.add(result); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); patternPanel.setAlignmentX(Component.CENTER_ALIGNMENT); localePanel.setAlignmentX(Component.CENTER_ALIGNMENT); resultPanel.setAlignmentX(Component.CENTER_ALIGNMENT); add(patternPanel); add(Box.createVerticalStrut(10)); add(localePanel); add(Box.createVerticalStrut(10)); add(resultPanel); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); reformat(); }
From source file:hr.fer.zemris.vhdllab.platform.gui.dialog.save.SaveDialog.java
public SaveDialog(LocalizationSource source, SaveContext context) { super(source); Validate.notNull(context, "Save variant can't be null"); // setup label JLabel label = new JLabel(getMainMessage(source, context)); int width = DIALOG_WIDTH - 2 * BORDER; int height = LABEL_HEIGHT - 2 * BORDER; label.setPreferredSize(new Dimension(width, height)); label.setBorder(BorderFactory.createEmptyBorder(BORDER, BORDER, BORDER, BORDER)); // setup check box list list = new CheckBoxList(); width = DIALOG_WIDTH - 2 * BORDER;//w w w .j a va 2 s .co m height = 0; // because list is a center component and it doesnt need // height list.setPreferredSize(new Dimension(width, height)); list.setBorder(BorderFactory.createEmptyBorder(BORDER, BORDER, BORDER, BORDER)); // setup select all and deselect all buttons JButton selectAll = new JButton(source.getMessage(SELECT_ALL_MESSAGE)); selectAll.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); selectAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { list.setSelectionToAll(true); } }); JButton deselectAll = new JButton(source.getMessage(DESELECT_ALL_MESSAGE)); deselectAll.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); deselectAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { list.setSelectionToAll(false); } }); Box selectBox = Box.createHorizontalBox(); selectBox.add(selectAll); selectBox.add(Box.createRigidArea(new Dimension(BORDER, BUTTON_HEIGHT))); selectBox.add(deselectAll); selectBox.setBorder(BorderFactory.createEmptyBorder(0, 0, BORDER, 0)); // setup ok and cancel buttons JButton ok = new JButton(source.getMessage(OK_MESSAGE)); ok.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeDialog(new ArrayList<File>()); } }); JButton cancel = new JButton(source.getMessage(CANCEL_MESSAGE)); cancel.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeDialog(null); } }); Box actionBox = Box.createHorizontalBox(); actionBox.add(ok); actionBox.add(Box.createRigidArea(new Dimension(BORDER, BUTTON_HEIGHT))); actionBox.add(cancel); actionBox.setBorder(BorderFactory.createEmptyBorder(BORDER, 0, BORDER, 0)); JPanel selectPanel = new JPanel(new BorderLayout()); selectPanel.add(selectBox, BorderLayout.EAST); JPanel actionPanel = new JPanel(new BorderLayout()); actionPanel.add(actionBox, BorderLayout.EAST); JCheckBox alwaysSave = new JCheckBox(source.getMessage(ALWAYS_SAVE_MESSAGE)); alwaysSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox checkBox = (JCheckBox) e.getSource(); Preferences preferences = Preferences.userNodeForPackage(SaveDialog.class); preferences.putBoolean(SHOULD_AUTO_SAVE, checkBox.isSelected()); } }); alwaysSave.setSelected(false); JPanel alwaysSavePanel = new JPanel(new BorderLayout()); alwaysSavePanel.add(alwaysSave, BorderLayout.WEST); JPanel lowerPanel = new JPanel(new BorderLayout()); lowerPanel.add(selectPanel, BorderLayout.NORTH); lowerPanel.add(alwaysSavePanel, BorderLayout.CENTER); lowerPanel.add(actionPanel, BorderLayout.SOUTH); this.setLayout(new BorderLayout()); JPanel messagePanel = new JPanel(new BorderLayout()); messagePanel.add(label, BorderLayout.NORTH); messagePanel.add(list, BorderLayout.CENTER); messagePanel.add(lowerPanel, BorderLayout.SOUTH); this.getContentPane().add(messagePanel, BorderLayout.CENTER); this.getRootPane().setDefaultButton(ok); this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); this.setTitle(getTitle(source, context)); }
From source file:events.MouseEventDemo.java
public MouseEventDemo() { super(new GridLayout(0, 1)); blankArea = new BlankArea(Color.YELLOW); add(blankArea);//from w w w.java2 s . c o m textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(200, 75)); add(scrollPane); //Register for mouse events on blankArea and the panel. blankArea.addMouseListener(this); addMouseListener(this); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:ChooseDropActionDemo.java
public ChooseDropActionDemo() { super("ChooseDropActionDemo"); for (int i = 15; i >= 0; i--) { from.add(0, "Source item " + i); }// w w w .j av a2 s .co m for (int i = 2; i >= 0; i--) { copy.add(0, "Target item " + i); move.add(0, "Target item " + i); } JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); dragFrom = new JList(from); dragFrom.setTransferHandler(new FromTransferHandler()); dragFrom.setPrototypeCellValue("List Item WWWWWW"); dragFrom.setDragEnabled(true); dragFrom.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JLabel label = new JLabel("Drag from here:"); label.setAlignmentX(0f); p.add(label); JScrollPane sp = new JScrollPane(dragFrom); sp.setAlignmentX(0f); p.add(sp); add(p, BorderLayout.WEST); JList moveTo = new JList(move); moveTo.setTransferHandler(new ToTransferHandler(TransferHandler.COPY)); moveTo.setDropMode(DropMode.INSERT); JList copyTo = new JList(copy); copyTo.setTransferHandler(new ToTransferHandler(TransferHandler.MOVE)); copyTo.setDropMode(DropMode.INSERT); p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); label = new JLabel("Drop to COPY to here:"); ; label.setAlignmentX(0f); p.add(label); sp = new JScrollPane(moveTo); sp.setAlignmentX(0f); p.add(sp); label = new JLabel("Drop to MOVE to here:"); label.setAlignmentX(0f); p.add(label); sp = new JScrollPane(copyTo); sp.setAlignmentX(0f); p.add(sp); p.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); add(p, BorderLayout.CENTER); ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); getContentPane().setPreferredSize(new Dimension(320, 315)); }
From source file:Main.java
public Main() { super(new BorderLayout()); // Create the demo's UI. startButton = new JButton("Start"); startButton.setActionCommand("start"); startButton.addActionListener(this); progressBar = new JProgressBar(0, 100); progressBar.setValue(0);// ww w. ja v a 2s .c o m // Call setStringPainted now so that the progress bar height // stays the same whether or not the string is shown. progressBar.setStringPainted(true); taskOutput = new JTextArea(5, 20); taskOutput.setMargin(new Insets(5, 5, 5, 5)); taskOutput.setEditable(false); JPanel panel = new JPanel(); panel.add(startButton); panel.add(progressBar); add(panel, BorderLayout.PAGE_START); add(new JScrollPane(taskOutput), BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:be.ac.ua.comp.scarletnebula.gui.windows.ServerPropertiesWindow.java
private JPanel getBottomPanel() { final JPanel bottomPanel = new JPanel(); final JButton okButton = ButtonFactory.createOkButton(); okButton.addActionListener(new ActionListener() { @Override/* w w w . j av a 2 s .com*/ public void actionPerformed(final ActionEvent e) { ServerPropertiesWindow.this.dispose(); } }); getRootPane().setDefaultButton(okButton); bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS)); bottomPanel.add(Box.createHorizontalGlue()); bottomPanel.add(okButton); bottomPanel.setBorder(BorderFactory.createEmptyBorder(0, 20, 20, 20)); return bottomPanel; }
From source file:events.MouseWheelEventDemo.java
public MouseWheelEventDemo() { super(new BorderLayout()); textArea = new JTextArea(); textArea.setEditable(false);//from w w w . j a va2 s .c o m scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(400, 250)); add(scrollPane, BorderLayout.CENTER); textArea.append("This text area displays information " + "about its mouse wheel events." + NEWLINE); //Register for mouse-wheel events on the text area. textArea.addMouseWheelListener(this); setPreferredSize(new Dimension(450, 350)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:events.MouseMotionEventDemo.java
public MouseMotionEventDemo() { super(new GridLayout(0, 1)); blankArea = new BlankArea(Color.YELLOW); add(blankArea);/*from w ww . j a v a 2 s.c o m*/ textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setPreferredSize(new Dimension(200, 75)); add(scrollPane); //Register for mouse events on blankArea and panel. blankArea.addMouseMotionListener(this); addMouseMotionListener(this); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:ProgressBarDemo2.java
public ProgressBarDemo2() { super(new BorderLayout()); // Create the demo's UI. startButton = new JButton("Start"); startButton.setActionCommand("start"); startButton.addActionListener(this); progressBar = new JProgressBar(0, 100); progressBar.setValue(0);//from w w w . ja v a2 s. c o m // Call setStringPainted now so that the progress bar height // stays the same whether or not the string is shown. progressBar.setStringPainted(true); taskOutput = new JTextArea(5, 20); taskOutput.setMargin(new Insets(5, 5, 5, 5)); taskOutput.setEditable(false); JPanel panel = new JPanel(); panel.add(startButton); panel.add(progressBar); add(panel, BorderLayout.PAGE_START); add(new JScrollPane(taskOutput), BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:net.pickapack.chart.LinePlotFrame.java
/** * Create a line plot frame.//from w w w . ja va 2s. c om * * @param linePlot the line plot * @param width the width * @param height the height */ public LinePlotFrame(LinePlot linePlot, int width, int height) { super(linePlot.getTitle()); this.linePlot = linePlot; this.numSubPlots = linePlot.getSubLinePlots().size(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.dataSets = new ArrayList<TimeSeriesCollection>(); this.dataSinks = new ArrayList<Map<SubLinePlotLine, Function<Double>>>(); for (SubLinePlot subLinePlot : linePlot.getSubLinePlots()) { TimeSeriesCollection dataSetsPerSubPlot = new TimeSeriesCollection(); this.dataSets.add(dataSetsPerSubPlot); HashMap<SubLinePlotLine, Function<Double>> dataSinksPerSubPlot = new HashMap<SubLinePlotLine, Function<Double>>(); this.dataSinks.add(dataSinksPerSubPlot); for (SubLinePlotLine subLinePlotLine : subLinePlot.getLines()) { TimeSeries timeSeries = new TimeSeries(subLinePlotLine.getTitle()); dataSetsPerSubPlot.addSeries(timeSeries); dataSinksPerSubPlot.put(subLinePlotLine, subLinePlotLine.getGetValueCallback()); } NumberAxis rangeAxis = new NumberAxis(subLinePlot.getTitleY()); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot = new XYPlot(dataSetsPerSubPlot, null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot); } JFreeChart chart = new JFreeChart(linePlot.getTitle(), plot); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(3600000.0); JPanel content = new JPanel(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(width, height)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(content); DataSink dataSink = new DataSink(); new Thread(dataSink).start(); }