Java Code Examples for javax.swing.JFrame#setPreferredSize()
The following examples show how to use
javax.swing.JFrame#setPreferredSize() .
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: SimpleDemo.java From lwjgl3-awt with MIT License | 6 votes |
public static void main(String[] args) { // Create the Vulkan instance VkInstance instance = createInstance(); VKData data = new VKData(); data.instance = instance; // <- set Vulkan instance JFrame frame = new JFrame("AWT test"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.setPreferredSize(new Dimension(600, 600)); frame.add(new AWTVKCanvas(data) { private static final long serialVersionUID = 1L; public void initVK() { @SuppressWarnings("unused") long surface = this.surface; // Do something with surface... } public void paintVK() { } }, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
Example 2
Source File: SimpleInfoBox.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
public SimpleInfoBox( final String title, final String text ) { frame = new JFrame( title ); final JTextArea textarea = new JTextArea( text ); final JPanel panel = new JPanel(); panel.add( textarea, BorderLayout.CENTER ); final JScrollPane pane = new JScrollPane( panel ); frame.add( pane, BorderLayout.CENTER ); frame.pack(); final Dimension d = pane.getSize(); d.setSize( d.width + 20, d.height + 10 ); pane.setSize( d ); pane.setPreferredSize( d ); frame.setPreferredSize( d ); frame.pack(); frame.setVisible( true ); }
Example 3
Source File: InternalFrameDemo.java From littleluck with Apache License 2.0 | 5 votes |
/** * main method allows us to run as a standalone demo. */ public static void main(String[] args) { JFrame frame = new JFrame(InternalFrameDemo.class.getAnnotation(DemoProperties.class).value()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new InternalFrameDemo()); frame.setPreferredSize(new Dimension(800, 600)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
Example 4
Source File: CacheUtils.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static void openCacheManager() { JFrame frame = new JFrame(); frame.setPreferredSize(new Dimension(800, 300)); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); File cacheRoot = getCacheRoot(); DataCacheViewer viewerPanel = new DataCacheViewer(cacheRoot); frame.getContentPane().add(viewerPanel.getPanel(), BorderLayout.CENTER); frame.pack(); // Center the application on the screen. GuiUtilities.centerOnScreen(frame); frame.setVisible(true); }
Example 5
Source File: FastCopyMainForm.java From FastCopy with Apache License 2.0 | 5 votes |
public void init() { frame = new JFrame("MHISoft FastCopy " + UI.version); frame.setContentPane(layoutPanel1); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //progressBar1.setVisible(false); progressBar1.setMaximum(100); progressBar1.setMinimum(0); progressPanel.setVisible(false); //frame.setPreferredSize(new Dimension(1200, 800)); frame.setPreferredSize(new Dimension(UserPreference.getInstance().getDimensionX(), UserPreference.getInstance().getDimensionY())); frame.pack(); /*position it*/ //frame.setLocationRelativeTo(null); // *** this will center your app *** PointerInfo a = MouseInfo.getPointerInfo(); Point b = a.getLocation(); int x = (int) b.getX(); int y = (int) b.getY(); frame.setLocation(x + 100, y); btnHelp.setBorder(null); frame.setVisible(true); componentsList = ViewHelper.getAllComponents(frame); setupFontSpinner(); ViewHelper.setFontSize(componentsList, UserPreference.getInstance().getFontSize()); }
Example 6
Source File: OSMMapTilePackagerUI.java From osmdroid with Apache License 2.0 | 5 votes |
public static void main(final String[] args) { final JFrame j = new OSMMapTilePackagerUI(); j.setPreferredSize(new Dimension(640, 400)); j.setDefaultCloseOperation(EXIT_ON_CLOSE); j.pack(); j.setVisible(true); }
Example 7
Source File: MultipleSubscribersHotObs.java From tutorials with MIT License | 5 votes |
private static void createAndShowGUI() { frame = new JFrame("Hot Observable Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setBackground(Color.GRAY); frame.setPreferredSize(new Dimension(500, 500)); frame.pack(); frame.setVisible(true); }
Example 8
Source File: Core32Test.java From lwjgl3-awt with MIT License | 4 votes |
public static void main(String[] args) { JFrame frame = new JFrame("AWT test"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.setPreferredSize(new Dimension(600, 600)); GLData data = new GLData(); data.samples = 4; data.swapInterval = 0; data.majorVersion = 3; data.minorVersion = 2; data.profile = GLData.Profile.CORE; AWTGLCanvas canvas; frame.add(canvas = new AWTGLCanvas(data) { private static final long serialVersionUID = 1L; int aspectUniform; public void initGL() { System.out.println("OpenGL version: " + effective.majorVersion + "." + effective.minorVersion + " (Profile: " + effective.profile + ")"); createCapabilities(); glClearColor(0.3f, 0.4f, 0.5f, 1); glBindVertexArray(glGenVertexArrays()); int vbo = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, new float[] { -0.5f, 0, 0, -0.5f, 0.5f, 0, 0.5f, 0, 0, 0.5f, -0.5f, 0 }, GL_STATIC_DRAW); glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0L); glEnableVertexAttribArray(0); int vs = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vs, "#version 150 core\nuniform float aspect;in vec2 vertex;void main(void){gl_Position=vec4(vertex/vec2(aspect, 1.0), 0.0, 1.0);}"); glCompileShader(vs); if (glGetShaderi(vs, GL_COMPILE_STATUS) == 0) throw new AssertionError("Could not compile vertex shader: " + glGetShaderInfoLog(vs)); int fs = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fs, "#version 150 core\nout vec4 color;void main(void){color=vec4(0.4, 0.6, 0.8, 1.0);}"); glCompileShader(fs); if (glGetShaderi(fs, GL_COMPILE_STATUS) == 0) throw new AssertionError("Could not compile fragment shader: " + glGetShaderInfoLog(fs)); int prog = glCreateProgram(); glAttachShader(prog, vs); glAttachShader(prog, fs); glLinkProgram(prog); if (glGetProgrami(prog, GL_LINK_STATUS) == 0) throw new AssertionError("Could not link program: " + glGetProgramInfoLog(prog)); glUseProgram(prog); aspectUniform = glGetUniformLocation(prog, "aspect"); } public void paintGL() { int w = getWidth(); int h = getHeight(); float aspect = (float) w / h; glClear(GL_COLOR_BUFFER_BIT); glViewport(0, 0, w, h); glUniform1f(aspectUniform, aspect); glDrawArrays(GL_TRIANGLES, 0, 6); this.swapBuffers(); this.repaint(); } }, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); frame.transferFocus(); Runnable renderLoop = new Runnable() { public void run() { if (!canvas.isValid()) return; canvas.render(); SwingUtilities.invokeLater(this); } }; SwingUtilities.invokeLater(renderLoop); }
Example 9
Source File: AWTTest.java From lwjgl3-awt with MIT License | 4 votes |
public static void main(String[] args) { JFrame frame = new JFrame("AWT test"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.setPreferredSize(new Dimension(600, 600)); GLData data = new GLData(); data.samples = 4; data.swapInterval = 0; AWTGLCanvas canvas; frame.add(canvas = new AWTGLCanvas(data) { private static final long serialVersionUID = 1L; public void initGL() { System.out.println("OpenGL version: " + effective.majorVersion + "." + effective.minorVersion + " (Profile: " + effective.profile + ")"); createCapabilities(); glClearColor(0.3f, 0.4f, 0.5f, 1); } public void paintGL() { int w = getWidth(); int h = getHeight(); float aspect = (float) w / h; double now = System.currentTimeMillis() * 0.001; float width = (float) Math.abs(Math.sin(now * 0.3)); glClear(GL_COLOR_BUFFER_BIT); glViewport(0, 0, w, h); glBegin(GL_QUADS); glColor3f(0.4f, 0.6f, 0.8f); glVertex2f(-0.75f * width / aspect, 0.0f); glVertex2f(0, -0.75f); glVertex2f(+0.75f * width/ aspect, 0); glVertex2f(0, +0.75f); glEnd(); swapBuffers(); } }, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); frame.transferFocus(); Runnable renderLoop = new Runnable() { public void run() { if (!canvas.isValid()) return; canvas.render(); SwingUtilities.invokeLater(this); } }; SwingUtilities.invokeLater(renderLoop); }