/** Runs a sample program that shows dropped files */ public static void main(String[] args) { javax.swing.JFrame frame = new javax.swing.JFrame("FileDrop"); // javax.swing.border.TitledBorder dragBorder = new javax.swing.border.TitledBorder( "Drop 'em" // ); final javax.swing.JTextArea text = new javax.swing.JTextArea(); frame.getContentPane().add(new javax.swing.JScrollPane(text), java.awt.BorderLayout.CENTER); new FileDrop( System.out, text, /*dragBorder,*/ new FileDrop.Listener() { public void filesDropped(java.io.File[] files, Point point) { for (int i = 0; i < files.length; i++) { try { text.append(files[i].getCanonicalPath() + "\n"); } // end try catch (java.io.IOException e) { } } // end for: through each dropped file } // end filesDropped }); // end FileDrop.Listener frame.setBounds(100, 100, 300, 400); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.show(); } // end main
public static void main(String[] args) throws Exception { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } UIManager.put("PopupMenuUI", "DropShadow.CustomPopupMenuUI"); JFrame frame = new JFrame(DropShadowDemo.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar mb = new JMenuBar(); frame.setJMenuBar(mb); JMenu menu = new JMenu("File"); mb.add(menu); menu.add(new JMenuItem("Open")); menu.add(new JMenuItem("Save")); menu.add(new JMenuItem("Close")); menu.add(new JMenuItem("Exit")); menu = new JMenu("Edit"); mb.add(menu); menu.add(new JMenuItem("Cut")); menu.add(new JMenuItem("Copy")); menu.add(new JMenuItem("Paste")); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add("North", new JButton("Button")); frame.getContentPane().add("Center", new JLabel("a label")); frame.getContentPane().add("South", new JCheckBox("checkbox")); frame.pack(); frame.setSize(200, 150); frame.setLocationRelativeTo(null); frame.show(); }
public static void main(String[] args) { final JFrame frame = new JFrame("Grid Monitor"); MonitorForm form = new MonitorForm(); frame.setContentPane(form.mainPanel); frame.pack(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.show(); }
/** * Displays an XYPlot with symbolic axes. * * @param frameTitle the frame title. * @param data the dataset. * @param chartTitle the chart title. * @param xAxisLabel the x axis label. * @param yAxisLabel the y axis label. */ private static void displayXYSymbolic( String frameTitle, XYDataset data, String chartTitle, String xAxisLabel, String yAxisLabel) { JFreeChart chart = createXYSymbolicPlot(chartTitle, xAxisLabel, yAxisLabel, data, true); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green)); JFrame frame = new ChartFrame(frameTitle, chart); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.show(); }
// TODO- debug public static void showHTML(String type, String htmlsource) { JFrame frame = new JFrame(); JEditorPane text = new JEditorPane(type, htmlsource); JScrollPane panel = new JScrollPane(text); frame.getContentPane().add(panel); frame.setSize(800, 600); int len = 20 < htmlsource.length() ? 20 : htmlsource.length(); frame.setTitle(htmlsource.substring(0, len)); frame.show(); }
public static void main(String[] args) { /* 构造函数有很多下面先介绍几个: JTable() JTable(int numRows, int numColumns) JTable(Object[][] rowData, Object[] columnNames) */ JTable example1 = new JTable(); // 看不到但存在 JTable example2 = new JTable(8, 6); final Object[] columnNames = { "姓名", "性别", "家庭地址", // 列名最好用final修饰 "电话号码", "生日", "工作", "收入", "婚姻状况", "恋爱状况" }; Object[][] rowData = { {"ddd", "男", "江苏南京", "1378313210", "03/24/1985", "学生", "寄生中", "未婚", "没"}, {"eee", "女", "江苏南京", "13645181705", "xx/xx/1985", "家教", "未知", "未婚", "好象没"}, {"fff", "男", "江苏南京", "13585331486", "12/08/1985", "汽车推销员", "不确定", "未婚", "有"}, {"ggg", "女", "江苏南京", "81513779", "xx/xx/1986", "宾馆服务员", "确定但未知", "未婚", "有"}, {"hhh", "男", "江苏南京", "13651545936", "xx/xx/1985", "学生", "流放中", "未婚", "无数次分手后没有"} }; JTable friends = new JTable(rowData, columnNames); friends.setPreferredScrollableViewportSize(new Dimension(600, 100)); // 设置表格的大小 friends.setRowHeight(30); // 设置每行的高度为20 friends.setRowHeight(0, 20); // 设置第1行的高度为15 friends.setRowMargin(5); // 设置相邻两行单元格的距离 friends.setRowSelectionAllowed(true); // 设置可否被选择.默认为false friends.setSelectionBackground(Color.white); // 设置所选择行的背景色 friends.setSelectionForeground(Color.red); // 设置所选择行的前景色 friends.setGridColor(Color.black); // 设置网格线的颜色 friends.selectAll(); // 选择所有行 friends.setRowSelectionInterval(0, 2); // 设置初始的选择行,这里是1到3行都处于选择状态 friends.clearSelection(); // 取消选择 friends.setDragEnabled(false); // 不懂这个 friends.setShowGrid(false); // 是否显示网格线 friends.setShowHorizontalLines(false); // 是否显示水平的网格线 friends.setShowVerticalLines(true); // 是否显示垂直的网格线 friends.setValueAt("tt", 0, 0); // 设置某个单元格的值,这个值是一个对象 friends.doLayout(); friends.setBackground(Color.lightGray); JScrollPane pane1 = new JScrollPane(example1); // JTable最好加在JScrollPane上 JScrollPane pane2 = new JScrollPane(example2); JScrollPane pane3 = new JScrollPane(friends); JPanel panel = new JPanel(new GridLayout(0, 1)); panel.setPreferredSize(new Dimension(600, 400)); panel.setBackground(Color.black); panel.add(pane1); panel.add(pane2); panel.add(pane3); JFrame frame = new JFrame("JTableDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(panel); frame.pack(); frame.show(); }
/** EdiDialog constructor comment. */ public static void test() { JFrame frame = new JFrame(); frame.addWindowListener(new CloseSaveWindowsListener()); frame.setBackground(ConfigurableSystemSettings.backgroundColor.getAWTColor()); frame.getContentPane().setLayout(new java.awt.BorderLayout()); frame.setBounds(50, 50, 400, 400); frame.show(); DialogNewElement dialog = new DialogNewElement(frame); dialog.show(); }
public static void main(String args[]) { JFrame f = new JFrame("JPasswordField3"); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel p1 = new JPanel(); // p1.setLayout(new GridLayout(4,2)); p1.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.WEST; // 设定Layout的位置 gbc.insets = new Insets(2, 2, 2, 2); // 设定与边界的距离(上,左,下,右) p1.setBorder(BorderFactory.createTitledBorder("您的基本数据")); JLabel l1 = new JLabel("姓名:"); JLabel l2 = new JLabel("性别:"); JLabel l3 = new JLabel("身高:"); JLabel l4 = new JLabel("体重:"); JPasswordField t1 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(10), "", 10); JPasswordField t2 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(1), "", 2); JPasswordField t3 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(5), "", 5); JPasswordField t4 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(5), "", 5); gbc.gridy = 1; gbc.gridx = 0; p1.add(l1, gbc); gbc.gridx = 1; p1.add(t1, gbc); gbc.gridy = 2; gbc.gridx = 0; p1.add(l2, gbc); gbc.gridx = 1; p1.add(t2, gbc); gbc.gridy = 3; gbc.gridx = 0; p1.add(l3, gbc); gbc.gridx = 1; p1.add(t3, gbc); gbc.gridy = 4; gbc.gridx = 0; p1.add(l4, gbc); gbc.gridx = 1; p1.add(t4, gbc); contentPane.add(p1); f.pack(); f.show(); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException { JFrame jf = new JFrame(); AttributesPanel colpal = new AttributesPanel(); colpal.setEntity(new FrameFact("hola")); colpal.setEntity(new FrameFact("hola")); jf.getContentPane().add(colpal); jf.pack(); jf.show(); jf.pack(); }
public static void main(String[] args) { JFrame frame = new JFrame("Cwiczenie5_4"); Container cp = frame.getContentPane(); Cwiczenie5_4 Cwiczenie5_4 = new Cwiczenie5_4(); cp.add(Cwiczenie5_4); frame.addKeyListener(Cwiczenie5_4.bar); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setLocation(300, 300); frame.pack(); frame.show(); Cwiczenie5_4.startGame(); }
/** * Vertically combined sample1 and sample2 and display it. * * @param frameTitle the frame title. * @param data1 the dataset 1. * @param data2 the dataset 2. */ private static void displayXYSymbolicCombinedVertically( String frameTitle, XYDataset data1, XYDataset data2) { String title = "Pollutant Vertically Combined"; String xAxisLabel = "Contamination and Type"; String yAxisLabel = "Pollutant"; // combine the x symbolic values of the two data sets String[] combinedXSymbolicValues = SampleXYSymbolicDataset.combineXSymbolicDataset((XisSymbolic) data1, (XisSymbolic) data2); // make master dataset... CombinedDataset data = new CombinedDataset(); data.add(data1); data.add(data2); // decompose data... XYDataset series0 = new SubSeriesDataset(data, 0); XYDataset series1 = new SubSeriesDataset(data, 1); // common horizontal and vertical axes SymbolicAxis hsymbolicAxis = new SymbolicAxis(xAxisLabel, combinedXSymbolicValues); SymbolicAxis vsymbolicAxis0 = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data1).getYSymbolicValues()); SymbolicAxis vsymbolicAxis1 = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data2).getYSymbolicValues()); // create the main plot... CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(hsymbolicAxis); // add the sub-plots... XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); XYPlot subplot0 = new XYPlot(series0, null, vsymbolicAxis0, renderer); XYPlot subplot1 = new XYPlot(series1, null, vsymbolicAxis1, renderer); mainPlot.add(subplot0, 1); mainPlot.add(subplot1, 1); // make the chart... JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); // and present it in a frame... JFrame frame = new ChartFrame(frameTitle, chart); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.show(); }
public static void Center(JFrame frame) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.show(); }
public BuildingTreeTableExample() { JFrame frame = new JFrame("BuildingTreeTableExample"); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); DefaultTreeModel defaultTreeModel = new DefaultTreeModel(root); toTree(defaultTreeModel, root); JTreeTable treeTable = new JTreeTable(new BuildingTreeTableModel(root)); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); frame.getContentPane().add(new JScrollPane(treeTable)); frame.pack(); frame.show(); }
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); } }); }
public Page2() { a = new JFrame("Game"); button = new JButton(); Icon ya = new ImageIcon(System.getProperty("user.dir") + "\\src\\Data\\Project\\G15\\game\\123.jpg"); JPanel panel = new JPanel(); button.setIcon(ya); button.addActionListener(this); panel.add(button); a.add(panel); // a.setLocation(400,0); a.pack(); a.show(); }
/** * Displays an overlaid XYPlot with X and Y symbolic data. * * @param frameTitle the frame title. * @param data1 the dataset 1. * @param data2 the dataset 2. */ private static void displayXYSymbolicOverlaid( String frameTitle, XYDataset data1, XYDataset data2) { String title = "Pollutant Overlaid"; String xAxisLabel = "Contamination and Type"; String yAxisLabel = "Pollutant"; // combine the x symbolic values of the two data sets String[] combinedXSymbolicValues = SampleXYSymbolicDataset.combineXSymbolicDataset((XisSymbolic) data1, (XisSymbolic) data2); // combine the y symbolic values of the two data sets String[] combinedYSymbolicValues = SampleXYSymbolicDataset.combineYSymbolicDataset((YisSymbolic) data1, (YisSymbolic) data2); // make master dataset... CombinedDataset data = new CombinedDataset(); data.add(data1); data.add(data2); // decompose data... XYDataset series0 = new SubSeriesDataset(data, 0); XYDataset series1 = new SubSeriesDataset(data, 1); // create overlaid plot... SymbolicAxis hsymbolicAxis = new SymbolicAxis(xAxisLabel, combinedXSymbolicValues); SymbolicAxis vsymbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues); XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); XYPlot plot = new XYPlot(series0, hsymbolicAxis, vsymbolicAxis, renderer1); XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); plot.setSecondaryDataset(0, series1); plot.setSecondaryRenderer(0, renderer2); // make the chart... JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); // and present it in a frame... JFrame frame = new ChartFrame(frameTitle, chart); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.show(); }
public static void main(String[] args) throws IOException { JFrame frame = new JFrame("Song Player"); JPanel pane = new JPanel(); JButton button1 = new JButton("Play Song"); frame.getContentPane().add(pane); pane.add(button1); frame.pack(); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.show(); button1.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { playSong(); } }); }
public AgentTimeJTextPane() throws UnsupportedEncodingException { // 初始化所有模块 frame = new JFrame("Maximo监控程序"); textPane = new JTextPane(); textPane.setCursor(new Cursor(Cursor.TEXT_CURSOR)); textPane.setText("java版本为:" + System.getProperty("java.version") + "\n换行"); // 设置主框架的布局 Container c = frame.getContentPane(); // c.setLayout(new BorderLayout()) JScrollPane jsp = new JScrollPane(textPane); // 新建一个滚动条界面,将文本框传入 c.add(jsp, BorderLayout.CENTER); /* * 文本框二 */ textPane2 = new JTextPane(); textPane2.setCursor(new Cursor(Cursor.TEXT_CURSOR)); JScrollPane jsp2 = new JScrollPane(textPane2); // 新建一个滚动条界面,将文本框传入 c.add(jsp2, BorderLayout.SOUTH); /* * 增加标签 */ Label label = new Label("java Version:" + System.getProperty("java.version")); c.add(label, BorderLayout.NORTH); // 利用无名内隐类,增加窗口事件 frame.addWindowListener( new WindowAdapter() { public void WindowClosing(WindowEvent e) { // 释放资源,退出程序 frame.dispose(); System.exit(0); } }); frame.setSize(700, 500); // 隐藏frame的标题栏,此功暂时关闭,以方便使用window事件 // setUndecorated(true); frame.setLocation(200, 150); frame.show(); }
/** * @param type * @param htmlsource * @author Jie Bao * @version 2003-11-06 */ public static void showHTML(String url) { JEditorPane jep = new JEditorPane(); jep.setEditable(false); try { jep.setPage(url); } catch (IOException e) { jep.setContentType("text/html"); jep.setText("<html>Could not load " + url + "</html>"); } JScrollPane scrollPane = new JScrollPane(jep); JFrame f = new JFrame(url); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(scrollPane); f.setSize(800, 600); f.show(); }
public static void main(String s[]) { if (s.length > 0) j2kfilename = s[0]; else j2kfilename = "girl"; System.out.println(j2kfilename); isApplet = false; JFrame f = new JFrame("ImageViewer"); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); JApplet applet = new ImageViewer(); f.getContentPane().add("Center", applet); applet.init(); f.pack(); f.setSize(new Dimension(550, 550)); f.show(); }
public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } Action action = new GloballyContextSensitiveAction("selectAll", "selectAll", "selectAll"); JMenuBar menubar = new JMenuBar(); JMenu menu = new JMenu("Actions"); menu.add(action); menubar.add(menu); JToolBar toolbar = new JToolBar(); toolbar.setRollover(true); toolbar.setFloatable(true); toolbar.add(action); JPanel contents = new JPanel(); String[] listData = new String[] {"item1", "item2", "item3", "item4", "item5 "}; JList list = new JList(listData); contents.add(new JScrollPane(list)); JTree tree = new JTree(); tree.setVisibleRowCount(10); contents.add(new JScrollPane(tree)); JTable table = new JTable(new DefaultTableModel(new String[] {"Name", "Type", "Modified"}, 10)); table.setPreferredScrollableViewportSize(new Dimension(100, 5 * table.getRowHeight())); contents.add(new JScrollPane(table)); contents.add(new JPanel()); JFrame frame = new JFrame("Globally Context Sensitive Actions - [email protected]"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(menubar); frame.getContentPane().add(contents); frame.getContentPane().add(toolbar, BorderLayout.NORTH); frame.pack(); frame.show(); }
/** * The main program for the AlerterTest class * * @param args The command line arguments */ public static void main(String[] args) { final JFrame frame = new JFrame("asdf"); // set up the main menubar JMenuBar menubar = new JMenuBar(); JMenu menu = new JMenu("Test"); JMenuItem item = new JMenuItem("Do Alert in 4 Seconds"); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { new Thread( new Runnable() { public void run() { try { Thread.currentThread().sleep(1000); } catch (Exception ex) { } try { System.out.println("calling"); Alerter alerter = Alerter.newInstance(); alerter.alert(frame); } catch (Exception e) { System.err.println("Couldn't load the library."); } } }) .start(); } }); menu.add(item); menubar.add(menu); // show the frame frame.setJMenuBar(menubar); frame.pack(); frame.setSize(100, 100); frame.show(); }
public JList7() { JFrame f = new JFrame("JList"); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); label = new JLabel(); list = new JList(s); list.setVisibleRowCount(5); list.setBorder(BorderFactory.createTitledBorder("您最喜欢到哪个国家玩呢?")); list.addListSelectionListener(this); contentPane.add(label, BorderLayout.NORTH); contentPane.add(new JScrollPane(list), BorderLayout.CENTER); f.pack(); f.show(); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
public TreeFrame() { frame = new JFrame("NSLookup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try { root = TreeFactory.createORBTree("localhost", "1234", root); } catch (InvalidName e) { System.out.println("No connection :( "); e.printStackTrace(); } ; DefaultTreeModel model = new DefaultTreeModel(root); // tree = new JTree(model); tree = new DNDTree(model); /* tree.addTreeSelectionListener(new TreeSelectionListener(){ public void valueChanged(TreeSelectionEvent e) { NamingContextTreeNode node = (NamingContextTreeNode)tree.getSelectionPath().getLastPathComponent(); System.out.println(node.getType()); } }); */ frame.getContentPane().add(tree); frame.setSize(400, 400); frame.show(); }
public static void main(String[] args) { dynetica.reaction.EquilibratedMassAction reaction = new dynetica.reaction.EquilibratedMassAction( "TestReaction", new dynetica.system.ReactiveSystem("Test")); try { reaction.setProperty("stoichiometry", "A + B + C + D -> E + F + K + L"); reaction.setProperty( "K", "k1 * [A] * sin([B]) * log([C]) / ([E]^[F] * [F]^100 * [K] * [L])"); javax.swing.JFrame frame = new javax.swing.JFrame(); frame.addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); frame.getContentPane().add(reaction.editor()); frame.pack(); frame.show(); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) { JFrame frame = new JFrame("Test"); frame.addWindowListener( new WindowAdapter() { /** @see java.awt.event.WindowAdapter#windowClosing(WindowEvent) */ public void windowClosing(WindowEvent e) { System.exit(0); } /** @see java.awt.event.WindowListener#windowClosed(WindowEvent) */ public void windowClosed(WindowEvent e) { System.exit(0); } }); frame.getContentPane().setLayout(new BorderLayout()); ImagePanel pan = new ImagePanel( new ImageIcon("/home/calum/images/content2.jpg"), 0, 0, 0.5, ImagePanel.NONE); pan.setLayout(new BorderLayout()); JPanel panel2 = new JPanel(); panel2.setLayout(new GridLayout(2, 2)); pan.setAllComponentsOpaque(false); panel2.setOpaque(false); pan.add(panel2, BorderLayout.CENTER); panel2.add(new JLabel("Name")); JTextField thru = new JTextField(""); thru.setOpaque(false); JTextField thru2 = new JTextField(""); thru2.setOpaque(false); panel2.add(thru); panel2.add(new JLabel("Email Address")); panel2.add(thru2); frame.getContentPane().add(pan, BorderLayout.CENTER); frame.setSize(600, 600); frame.show(); }
public static void main(String[] args) { // Create some components and a FontChooser dialog final JFrame frame = new JFrame("demo"); final JButton button = new JButton("Push Me!"); final FontChooser chooser = new FontChooser(frame); // Handle button clicks button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Pop up the dialog chooser.show(); // Get the user's selection Font font = chooser.getSelectedFont(); // If not cancelled, set the button font if (font != null) button.setFont(font); } }); // Display the demo frame.getContentPane().add(button); frame.setSize(200, 100); frame.show(); }
/** Stand alone testing. */ public static void main(String[] args) { try { JFrame frame = new JFrame("JargonTree"); JargonTree tree = new JargonTree(args, null); JScrollPane pane = new JScrollPane(tree); pane.setPreferredSize(new Dimension(800, 600)); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); frame.getContentPane().add(pane, BorderLayout.NORTH); frame.pack(); frame.show(); frame.validate(); } catch (Throwable e) { e.printStackTrace(); System.out.println(((SRBException) e).getStandardMessage()); } }
public void show() { createShadowBorder(); super.show(); setSize(getWidth() + SHADOW_WIDTH, getHeight() + SHADOW_WIDTH); }
public static void main(String args[]) { JFrame frame = new JFrame("Drag Image"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); final Clipboard clipboard = frame.getToolkit().getSystemClipboard(); final JLabel label = new JLabel(); // Icon icon = new ImageIcon("/home/j2ee/Desktop/war.103.gif"); // label.setIcon(icon); label.setTransferHandler(new ImageSelection()); MouseListener mouseListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent comp = (JComponent) e.getSource(); TransferHandler handler = comp.getTransferHandler(); handler.exportAsDrag(comp, e, TransferHandler.COPY); } }; label.addMouseListener(mouseListener); JScrollPane pane = new JScrollPane(label); contentPane.add(pane, BorderLayout.CENTER); JButton copy = new JButton("Copy"); copy.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // fire TransferHandler's built-in copy // action with a new actionEvent having // "label" as the source Action copyAction = TransferHandler.getCopyAction(); copyAction.actionPerformed( new ActionEvent( label, ActionEvent.ACTION_PERFORMED, (String) copyAction.getValue(Action.NAME), EventQueue.getMostRecentEventTime(), 0)); } }); JButton clear = new JButton("Clear"); clear.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { label.setIcon(null); } }); JButton paste = new JButton("Paste"); paste.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { // use TransferHandler's built-in // paste action Action pasteAction = TransferHandler.getPasteAction(); pasteAction.actionPerformed( new ActionEvent( label, ActionEvent.ACTION_PERFORMED, (String) pasteAction.getValue(Action.NAME), EventQueue.getMostRecentEventTime(), 0)); } }); JPanel p = new JPanel(); p.add(copy); p.add(clear); p.add(paste); contentPane.add(p, BorderLayout.SOUTH); frame.setSize(300, 300); frame.show(); }