javax.swing.JFrame Java Examples

The following examples show how to use javax.swing.JFrame. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisplayChangesException.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void test() throws Exception {
    SunToolkit.createNewAppContext();
    EventQueue.invokeAndWait(() -> {
        frame = new JFrame();
        final JButton b = new JButton();
        b.addPropertyChangeListener(evt -> {
            if (!SunToolkit.isDispatchThreadForAppContext(b)) {
                System.err.println("Wrong thread:" + currentThread());
                fail = true;
            }
        });
        frame.add(b);
        frame.setSize(100, 100);
        frame.setLocationRelativeTo(null);
        frame.pack();
    });
    go.await();
    EventQueue.invokeAndWait(() -> {
        frame.dispose();
    });
}
 
Example #2
Source File: UpdateUIRecursionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public UpdateUIRecursionTest() {
    super("UpdateUIRecursionTest");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 400);

    String[] listData = {
        "First", "Second", "Third", "Fourth", "Fifth", "Sixth"
    };

    tree = new JTree(listData);
    renderer = new DefaultTreeCellRenderer();
    getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
    tree.setCellRenderer(this);

    setVisible(true);
}
 
Example #3
Source File: LineNumber.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args)
{
	JFrame frame = new JFrame("LineNumberDemo");
	frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

	JPanel panel = new JPanel();
	frame.setContentPane( panel );
	panel.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
	panel.setLayout(new BorderLayout());

	JTextPane textPane = new JTextPane();
	textPane.setFont( new Font("monospaced", Font.PLAIN, 12) );
	textPane.setText("abc");

	JScrollPane scrollPane = new JScrollPane(textPane);
	panel.add(scrollPane);
	scrollPane.setPreferredSize(new Dimension(300, 250));

	LineNumber lineNumber = new LineNumber( textPane );
	scrollPane.setRowHeaderView( lineNumber );

	frame.pack();
	frame.setVisible(true);
}
 
Example #4
Source File: AddAndMoveGraphicsApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Starting point of this application.
 * 
 * @param args
 *            arguments to this application.
 */
public static void main(String[] args) {
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      try {
        // instance of this application
        AddAndMoveGraphicsApp addGraphicsApp = new AddAndMoveGraphicsApp();

        // create the UI, including the map, for the application.
        JFrame appWindow = addGraphicsApp.createWindow();
        appWindow.add(addGraphicsApp.createUI());
        appWindow.setVisible(true);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  });
}
 
Example #5
Source File: SetRootPaneSkin.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Opens a sample frame under the specified skin.
 * 
 * @param skin
 *            Skin.
 */
private void openSampleFrame(SubstanceSkin skin) {
    JFrame sampleFrame = new JFrame(skin.getDisplayName());
    sampleFrame.setLayout(new FlowLayout());
    JButton defaultButton = new JButton("active");
    JButton button = new JButton("default");
    JButton disabledButton = new JButton("disabled");
    disabledButton.setEnabled(false);
    sampleFrame.getRootPane().setDefaultButton(defaultButton);

    sampleFrame.add(defaultButton);
    sampleFrame.add(button);
    sampleFrame.add(disabledButton);

    sampleFrame.setVisible(true);
    sampleFrame.pack();
    sampleFrame.setLocationRelativeTo(null);
    sampleFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    sampleFrame.setIconImage(new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR));

    SubstanceCortex.RootPaneScope.setSkin(sampleFrame.getRootPane(), skin);
    SwingUtilities.updateComponentTreeUI(sampleFrame);
    sampleFrame.repaint();
}
 
Example #6
Source File: ProgressPanel.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
public ProgressPanel(JFrame owner, String message, boolean modal) {
		super(owner, modal);
		title = message;
		setTitle(message);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
//		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		int x = 100;
		int y = 100;
		if (MainWindow.frame != null) {
			x = MainWindow.frame.getX() + MainWindow.frame.getWidth()/2 - (message.length()*9)/2;
			y = MainWindow.frame.getY() + MainWindow.frame.getHeight()/2;
		} else {
			Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
			x = (int) ((dimension.getWidth() - this.getWidth()) / 2);
			y = (int) ((dimension.getHeight() - this.getHeight()) / 2);
		}
		setBounds(100, 100, message.length()*11, 10);
	
		    this.setLocation(x, y);
	}
 
Example #7
Source File: DemoTheatreApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Starting point of this application.
 * 
 * @param args arguments to this application.
 */
public static void main(String[] args) {

  // Tip: Use HTTP request intercepter such as Fiddler to track requests
  // ProxySetup.setupProxy("localhost", 8888);

  // create the UI, including the map, for the application
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      try {
        DemoTheatreApp app = new DemoTheatreApp();
        JFrame appWindow = app.createWindow();
        appWindow.add(app.createUI());
        appWindow.setVisible(true);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  });
}
 
Example #8
Source File: JButtonPaintNPE.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args)
        throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(() -> {
        frame = new JFrame();
        frame.add(new JButton() {
            @Override
            protected void paintComponent(final Graphics g) {
                Graphics gg = new BufferedImage(getWidth(), getHeight(),
                              BufferedImage.TYPE_INT_ARGB).createGraphics();
                super.paintComponent(gg);
                gg.dispose();
            }
        });
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    sleep();
    SwingUtilities.invokeAndWait(() -> {
        if (frame != null) {
            frame.dispose();
        }
    });
}
 
Example #9
Source File: RaceGUI.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a new instance of RaceGUI
 */
public RaceGUI(String appName) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JFrame f = new JFrame(appName);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLayout(new BorderLayout());
    
    // Add Track view
    track = new TrackView();
    f.add(track, BorderLayout.CENTER);
    
    // Add control panel
    controlPanel = new RaceControlPanel();
    f.add(controlPanel, BorderLayout.SOUTH);
    
    f.pack();
    f.setVisible(true);
}
 
Example #10
Source File: RobotUtils.java    From karate with MIT License 6 votes vote down vote up
public static void highlight(int x, int y, int width, int height, int time) {
    JFrame f = new JFrame();
    f.setUndecorated(true);
    f.setBackground(new Color(0, 0, 0, 0));
    f.setAlwaysOnTop(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setType(JFrame.Type.UTILITY);
    f.setFocusableWindowState(false);
    f.setAutoRequestFocus(false);
    f.setLocation(x, y);
    f.setSize(width, height);
    f.getRootPane().setBorder(BorderFactory.createLineBorder(Color.RED, 3));
    f.setVisible(true);
    delay(time);
    f.dispose();
}
 
Example #11
Source File: RSClient.java    From osrsclient with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IrcException, IOException {

		Toolkit.getDefaultToolkit().setDynamicLayout(true);
		System.setProperty("sun.awt.noerasebackground", "true");
		JFrame.setDefaultLookAndFeelDecorated(true);
		JDialog.setDefaultLookAndFeelDecorated(true);

		try {
			UIManager.setLookAndFeel("de.muntjak.tinylookandfeel.TinyLookAndFeel");

		} catch (Exception e) {
			e.printStackTrace();
		}

		initUI();
	}
 
Example #12
Source File: EmployeeListFrame.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param emp
 *            An array of employees.
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
private static JFrame printEmployees(final ArrayList<Employee> emp)
		throws ParserConfigurationException, SAXException, IOException {
	TableEModel m = new TableEModel(emp);
	JTable t = new JTable(m);
	JPanel panel = new JPanel();
	JFrame fram = new JFrame("Employees");
	panel.setLayout(new BorderLayout());
	JScrollPane tableC = new JScrollPane(t);
	tableC.getViewport().add(t);
	panel.add(tableC);
	fram.getContentPane().add(panel);
	fram.pack();
	fram.setVisible(true);
	return fram;
}
 
Example #13
Source File: SnapshotTool.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructor ComponentImage
 * @param comp
 */
public ComponentImage(Component comp) {
  c = comp;
  if(comp instanceof JFrame) {
    comp = ((JFrame) comp).getContentPane();
  } else if(comp instanceof JDialog) {
    comp = ((JDialog) comp).getContentPane();
  }
  image = new BufferedImage(comp.getWidth(), comp.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
  if(comp instanceof Renderable) {
    image = ((Renderable) comp).render(image);
  } else {
    java.awt.Graphics g = image.getGraphics();
    comp.paint(g);
    g.dispose();
  }
}
 
Example #14
Source File: JPolicyMappings.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
private void addPressed() {
	Container container = getTopLevelAncestor();

	DPolicyMappingChooser dPolicyMappingChooser = null;

	if (container instanceof JDialog) {
		dPolicyMappingChooser = new DPolicyMappingChooser((JDialog) container, title, null);
	} else {
		dPolicyMappingChooser = new DPolicyMappingChooser((JFrame) container, title, null);
	}
	dPolicyMappingChooser.setLocationRelativeTo(container);
	dPolicyMappingChooser.setVisible(true);

	PolicyMapping newPolicyMapping = dPolicyMappingChooser.getPolicyMapping();

	if (newPolicyMapping == null) {
		return;
	}

	policyMappings = PolicyMappingsUtil.add(newPolicyMapping, policyMappings);

	populate();
	selectPolicyMappingInTable(newPolicyMapping);
}
 
Example #15
Source File: OptimalPrimitives.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void createAndShowGUI() {    
    JFrame f = new JFrame("OptimalPrimitives");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(320, 300);
    f.add(new OptimalPrimitives());
    f.setVisible(true);
}
 
Example #16
Source File: Test6541987.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    String title = getClass().getName();
    JFrame frame = new JFrame(title);
    frame.setVisible(true);

    Color color = JColorChooser.showDialog(frame, title, Color.BLACK);
    if (color != null) {
        throw new Error("unexpected color: " + color);
    }
    frame.setVisible(false);
    frame.dispose();
}
 
Example #17
Source File: NonEditabilityTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    //Ensure we don't have a bogus stored value
    PropUtils.putSortOrder(PropertySheet.UNSORTED);

    JFrame jf = new JFrame();
    jf.getContentPane().setLayout(new BorderLayout());
    sheet = new PropertySheet();
    jf.getContentPane().add (sheet);

    jf.setBounds (20, 20, 200, 400);
    frame = jf;
    new WaitWindow(jf);
}
 
Example #18
Source File: RendererDisplayerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public WaitWindow(JFrame f) {
    f.addWindowListener(this);
    f.show();
    if (!shown) {
        synchronized(this) {
            try {
                //System.err.println("Waiting for window");
                wait(5000);
            } catch (Exception e) {}
        }
    }
}
 
Example #19
Source File: CardTable.java    From Think-Java-Exercises with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
   // make the frame
   JFrame frame = new JFrame("Card Table");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   // add the CardTable
   String cardset = "cardset-oxymoron";
   Canvas canvas = new CardTable(cardset);
   frame.getContentPane().add(canvas);

   // show the frame
   frame.pack();
   frame.setVisible(true);
}
 
Example #20
Source File: PreferenciesDialog.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
public PreferenciesDialog(JFrame mainFrame, List<Preferences> list,
                          Engine engine) {
    super(mainFrame, true);
    this.list = list;
    this.engine = engine;
    JTabbedPane pane = new JTabbedPane();
    for (Preferences p : list) {
        pane.addTab(p.getTitle(), p.createComponent());
    }
    setMainPane(pane);
    pack();
    this.setMinimumSize(new Dimension(800, 510));
    centerDialog();
    Options.loadOptions(this);
}
 
Example #21
Source File: LWDispatcherMemoryLeakTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void init() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame();
            frame.setLayout(new FlowLayout());
            button = new WeakReference<JButton>(new JButton("Text"));
            p = new WeakReference<JPanel>(new JPanel(new FlowLayout()));
            p.get().add(button.get());
            frame.add(p.get());

            frame.setBounds(500, 400, 200, 200);
            frame.setVisible(true);
        }
    });

    Util.waitTillShown(button.get());
    Util.clickOnComp(button.get(), new Robot());

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.remove(p.get());
        }
    });

    Util.waitForIdle(null);
    assertGC();
}
 
Example #22
Source File: RestAction.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
public RestAction(WorldObject playerCharacter, ImageInfoReader imageInfoReader, SoundIdReader soundIdReader, World world, WorldPanel parent, DungeonMaster dungeonMaster, JFrame parentFrame) {
	super();
	this.playerCharacter = playerCharacter;
	this.imageInfoReader = imageInfoReader;
	this.soundIdReader = soundIdReader;
	this.world = world;
	this.parent = parent;
	this.dungeonMaster = dungeonMaster;
	this.parentFrame = parentFrame;
}
 
Example #23
Source File: Test6541987.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    String title = getClass().getName();
    JFrame frame = new JFrame(title);
    frame.setVisible(true);

    Color color = JColorChooser.showDialog(frame, title, Color.BLACK);
    if (color != null) {
        throw new Error("unexpected color: " + color);
    }
    frame.setVisible(false);
    frame.dispose();
}
 
Example #24
Source File: RTabbedPaneTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void showDialog() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame(RTabbedPaneTest.class.getSimpleName());
            frame.setName("frame-" + RTabbedPaneTest.class.getSimpleName());
            frame.getContentPane().add(new TabbedPaneDemo(), BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);
        }
    });
}
 
Example #25
Source File: MissingGlyphTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void glyphTest() {
    frame = new JFrame("Test");
    frame.add(new MyComponent());
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setSize(200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example #26
Source File: Test6199676.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();

        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    }
    else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    }
    else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    }
    catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
 
Example #27
Source File: MapInspector.java    From coordination_oru with GNU General Public License v3.0 5 votes vote down vote up
private void createFrame() {
	//Scrolling
	//JScrollPane sp = new JScrollPane(this);       
	JFrame f = new JFrame("Map inspector");
	//f.setContentPane(sp);
	f.setContentPane(this);
	f.setSize(1280,1024);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	f.setVisible(true);
}
 
Example #28
Source File: ExportActionListener.java    From collect-earth with MIT License 5 votes vote down vote up
public ExportActionListener(DataFormat exportFormat, RecordsToExport recordsToExport, JFrame frame,
		LocalPropertiesService localPropertiesService, DataImportExportService dataExportService,
		EarthSurveyService earthSurveyService) {
	this.exportFormat = exportFormat;
	this.frame = frame;
	this.localPropertiesService = localPropertiesService;
	this.dataExportService = dataExportService;
	this.earthSurveyService = earthSurveyService;
	this.recordsToExport = recordsToExport;
}
 
Example #29
Source File: JComboBoxTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void showDialog() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame(JComboBoxTest.class.getSimpleName());
            frame.setName("frame-" + JComboBoxTest.class.getSimpleName());
            frame.getContentPane().add(new ComboBoxDemo(), BorderLayout.CENTER);
            frame.pack();
            frame.setAlwaysOnTop(true);
            frame.setVisible(true);
        }
    });
}
 
Example #30
Source File: Regression_116616_swing.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void componentShown( ComponentEvent cev )
{
	JFrame jf = (JFrame) cev.getComponent( );
	Rectangle r = jf.getBounds( );
	setLocation( r.x, r.y + r.height );
	setSize( r.width, 50 );
	setVisible( true );
}