public int getTitleHeight(Component c) { int th = 21; int fh = getBorderInsets(c).top + getBorderInsets(c).bottom; if (c instanceof JDialog) { JDialog dialog = (JDialog) c; th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1; if (dialog.getJMenuBar() != null) { th -= dialog.getJMenuBar().getSize().height; } } else if (c instanceof JInternalFrame) { JInternalFrame frame = (JInternalFrame) c; th = frame.getSize().height - frame.getRootPane().getSize().height - fh - 1; if (frame.getJMenuBar() != null) { th -= frame.getJMenuBar().getSize().height; } } else if (c instanceof JRootPane) { JRootPane jp = (JRootPane) c; if (jp.getParent() instanceof JFrame) { JFrame frame = (JFrame) c.getParent(); th = frame.getSize().height - frame.getContentPane().getSize().height - fh - 1; if (frame.getJMenuBar() != null) { th -= frame.getJMenuBar().getSize().height; } } else if (jp.getParent() instanceof JDialog) { JDialog dialog = (JDialog) c.getParent(); th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1; if (dialog.getJMenuBar() != null) { th -= dialog.getJMenuBar().getSize().height; } } } return th; }
// function to center the frame public static void center(JFrame jfrm) { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int width = jfrm.getSize().width; int height = jfrm.getSize().height; int x = (dim.width - width) / 2; int y = (dim.height - height) / 2; jfrm.setLocation(x, y); }
public static void main(String[] args) { TableModelDemo applet = new TableModelDemo(); JFrame frame = new JFrame(); // EXIT_ON_CLOSE == 3 frame.setDefaultCloseOperation(3); frame.setTitle("TableModelDemo"); frame.getContentPane().add(applet, BorderLayout.CENTER); applet.init(); applet.start(); frame.setSize(500, 220); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation( (d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); }
public PlayGamePanel(JFrame frame, BoardConfiguration bc) { this.bc = bc; this.frame = frame; ImageIcon icon = new ImageIcon("ent.jpg"); this.image = icon.getImage(); this.one = new TransparentButton("1 Player"); this.two = new TransparentButton("2 Players"); this.three = new TransparentButton("3 Players"); this.four = new TransparentButton("4 Players"); this.setSize(frame.getSize()); this.setLocation(0, 0); this.setLayout(null); one.setBounds(450, 140, 200, 40); two.setBounds(450, 200, 200, 40); three.setBounds(450, 260, 200, 40); four.setBounds(450, 320, 200, 40); this.add(one); this.add(two); this.add(three); this.add(four); this.back = new TransparentButton("Back"); back.setBounds(450, 380, 200, 40); this.add(back); this.one.setFont(new Font("calibri", Font.ITALIC, 30)); this.two.setFont(new Font("calibri", Font.ITALIC, 30)); this.three.setFont(new Font("calibri", Font.ITALIC, 30)); this.four.setFont(new Font("calibri", Font.ITALIC, 30)); this.back.setFont(new Font("calibri", Font.ITALIC, 30)); this.one.addMouseListener(this); this.two.addMouseListener(this); this.three.addMouseListener(this); this.four.addMouseListener(this); this.back.addMouseListener(this); this.back.setForeground(Color.red); }
public static void lockInMinSize(final JFrame frame) { // Ensures user cannot resize frame to be smaller than frame is right now. final int origX = frame.getSize().width; final int origY = frame.getSize().height; // frame.setSize(new Dimension(origX, origY)); frame.addComponentListener( new java.awt.event.ComponentAdapter() { @Override public void componentResized(ComponentEvent event) { frame.setSize(Math.max(frame.getWidth(), origX), Math.max(frame.getHeight(), origY)); frame.repaint(); } }); }
/** Sets the location on the given dialog for the given index. */ private void setLocation(JDialog dialog, int index) { Rectangle bounds = dialog.getBounds(); JFrame frame = findOwner(); Dimension dim; if (frame == null) { dim = Toolkit.getDefaultToolkit().getScreenSize(); } else { dim = frame.getSize(); } int x = (int) (150 * Math.cos(index * 15 * (Math.PI / 180))); int y = (int) (150 * Math.sin(index * 15 * (Math.PI / 180))); x += (dim.width - bounds.width) / 2; y += (dim.height - bounds.height) / 2; dialog.setLocation(x, y); }
/** * Method which creates a new GUI, and calls helper methods to set up the listeners for all the * buttons on the board. * * @throws IOException */ public void init() throws IOException { gui = new GUI(board); setCurrentSide(WHITE); JFrame f = new JFrame("Fighting Illini Chess"); f.add(gui.getGUI()); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // ensures the frame is the minimum size it needs to be // in order display the components within it f.pack(); // ensures the minimum size is enforced. f.setMinimumSize(f.getSize()); f.setVisible(true); // set up and add button action listeners initializeListeners(); addListeners(); }
static void showFrame(String title) { JFrame frame = new JFrame(title); frame.setSize(400, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 将画窗置于屏幕中央 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.setVisible(true); }
public static void centerFrame(JFrame frame) { Dimension frameSize = frame.getSize(); frame.setLocation( what(frameSize.width, screenSize.width), what(frameSize.height, screenSize.height)); frame.setVisible(true); }
/** * The Processing Plugin. Refer to Processing.__applet to get at the __applet. * * <p>E.g. var P = Java.type('fieldprocessing.Processing').__applet * * <p>This adds a command "Bridge box to Processing". Run that to move this box (and any children) * into the Processing draw cycle. Then you can write things like: * * <p>P.background(0) // sets background to black */ public class Processing extends Execution { public static final Dict.Prop<FieldProcessingAppletDelgate> P = new Dict.Prop<FieldProcessingAppletDelgate>("P") .toCannon() .type() .doc("the Processing Applet. e.g. `_.P.background(0)` sets the background to black."); private ProcessingExecution processingExecution; public FieldProcessingApplet __applet; public static FieldProcessingAppletDelgate applet; private List<Runnable> queue = new ArrayList<>(); protected JFrame frame; int sizeX = AutoPersist.persist( "processing_sizeX", () -> 400, x -> Math.min(2560, Math.max(100, x)), (x) -> frame.getSize().width); int sizeY = AutoPersist.persist( "processing_sizeY", () -> 400, x -> Math.min(2560, Math.max(100, x)), (x) -> frame.getSize().height); public interface MouseHandler { public void handle(FieldProcessingApplet applet, Object /*MouseEvent or MouseMoveEvent*/ event); } public interface KeyHandler { public void handle(FieldProcessingApplet applet, processing.event.KeyEvent event); } public Processing(Box root) { super(null); Log.log("startup.processing", " processing plugin is starting up "); frame = new JFrame("Field/Processing"); __applet = new FieldProcessingApplet( sizeX, sizeY, queue, this, s -> { if (getLastErrorOutput() != null) getLastErrorOutput().accept(new Pair<>(-1, s)); }); __applet.init(); __applet.loop(); frame.add(__applet, BorderLayout.CENTER); frame.setSize(sizeX, sizeY); frame.setVisible(true); frame.validate(); applet = new FieldProcessingAppletDelgate(__applet); this.properties.put(P, applet); Log.log("startup.processing", " searching for boxes that need processing support "); Log.log("startup.processing", " processing plugin has finished starting up "); } private Stream<Box> selection() { return breadthFirst(both()).filter(x -> x.properties.isTrue(Mouse.isSelected, false)); } public Execution.ExecutionSupport support(Box box, Dict.Prop<String> prop) { FunctionOfBox<Boolean> ef = this.properties.get(executionFilter); if (box == this || ef == null || ef.apply(box)) return wrap(box, prop); return null; } public Consumer<Pair<Integer, String>> lastErrorOutput; public Consumer<Pair<Integer, String>> getLastErrorOutput() { return lastErrorOutput; } private Execution.ExecutionSupport wrap(Box box, Dict.Prop<String> prop) { return new Execution.ExecutionSupport() { @Override public void executeTextFragment( String textFragment, String suffix, Consumer<String> success, Consumer<Pair<Integer, String>> lineErrors) { System.out.println(" WRAPPED :" + textFragment); queue.add( () -> { Execution delegateTo = box.find(Execution.execution, box.upwards()) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); s.executeTextFragment(textFragment, "", success, lineErrors); }); } @Override public Object getBinding(String name) { Execution delegateTo = box.find(Execution.execution, box.upwards()) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); return s.getBinding(name); } @Override public void executeAll( String allText, Consumer<Pair<Integer, String>> lineErrors, Consumer<String> success) { System.out.println(" WRAPPED :" + allText); queue.add( () -> { Execution delegateTo = box.find(Execution.execution, box.upwards()) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); s.executeAll(allText, lineErrors, success); }); } @Override public String begin( Consumer<Pair<Integer, String>> lineErrors, Consumer<String> success, Map<String, Object> initiator) { lastErrorOutput = lineErrors; Execution delegateTo = box.find(Execution.execution, box.upwards()) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); String name = s.begin(lineErrors, success, initiator); if (name == null) return null; Supplier<Boolean> was = box.properties.removeFromMap(Boxes.insideRunLoop, name); String newName = name.replace("main.", "processing."); box.properties.putToMap(Boxes.insideRunLoop, newName, was); box.first(IsExecuting.isExecuting).ifPresent(x -> x.accept(box, newName)); return name; } @Override public void end(Consumer<Pair<Integer, String>> lineErrors, Consumer<String> success) { System.out.println(" WRAPPED (end)"); Execution delegateTo = box.find(Execution.execution, box.upwards()) .filter(x -> x != Processing.this) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); s.end(lineErrors, success); } @Override public void setConsoleOutput(Consumer<String> stdout, Consumer<String> stderr) { System.out.println(" WRAPPED (stdout)"); Execution delegateTo = box.find(Execution.execution, box.upwards()) .filter(x -> x != Processing.this) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); s.setConsoleOutput(stdout, stderr); } @Override public void completion(String allText, int line, int ch, Consumer<List<Completion>> results) { System.out.println(" WRAPPED (completion) " + allText); Execution delegateTo = box.find(Execution.execution, box.upwards()) .filter(x -> x != Processing.this) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); s.completion(allText, line, ch, results); } @Override public void imports(String allText, int line, int ch, Consumer<List<Completion>> results) { System.out.println(" WRAPPED (imports) " + allText); Execution delegateTo = box.find(Execution.execution, box.upwards()) .filter(x -> x != Processing.this) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); s.imports(allText, line, ch, results); } @Override public String getCodeMirrorLanguageName() { Execution delegateTo = box.find(Execution.execution, box.upwards()) .filter(x -> x != Processing.this) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); return s.getCodeMirrorLanguageName(); } @Override public String getDefaultFileExtension() { Execution delegateTo = box.find(Execution.execution, box.upwards()) .filter(x -> x != Processing.this) .findFirst() .orElseThrow( () -> new IllegalArgumentException( " can't instantiate Processing execution - no default execution found")); Execution.ExecutionSupport s = delegateTo.support(box, prop); return s.getDefaultFileExtension(); } }; } }
protected void createAndShowGUI() { System.setProperty("swing.defaultlaf", UIManager.getSystemLookAndFeelClassName()); image = DavGatewayTray.loadImage("tray.png"); image2 = DavGatewayTray.loadImage(AwtGatewayTray.TRAY_ACTIVE_PNG); inactiveImage = DavGatewayTray.loadImage(AwtGatewayTray.TRAY_INACTIVE_PNG); mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setTitle(BundleMessage.format("UI_DAVMAIL_GATEWAY")); mainFrame.setIconImage(image); JPanel errorPanel = new JPanel(); errorPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_LAST_MESSAGE"))); errorPanel.setLayout(new BoxLayout(errorPanel, BoxLayout.X_AXIS)); errorArea = new JTextPane(); errorArea.setEditable(false); errorArea.setBackground(mainFrame.getBackground()); errorLabel = new JLabel(); errorPanel.add(errorLabel); errorPanel.add(errorArea); JPanel messagePanel = new JPanel(); messagePanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_LAST_LOG"))); messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.X_AXIS)); messageArea = new JTextPane(); messageArea.setText(BundleMessage.format("LOG_STARTING_DAVMAIL")); messageArea.setEditable(false); messageArea.setBackground(mainFrame.getBackground()); messagePanel.add(messageArea); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.add(errorPanel); mainPanel.add(messagePanel); mainFrame.add(mainPanel); aboutFrame = new AboutFrame(); settingsFrame = new SettingsFrame(); buildMenu(); mainFrame.setMinimumSize(new Dimension(400, 180)); mainFrame.pack(); // workaround MacOSX if (mainFrame.getSize().width < 400 || mainFrame.getSize().height < 180) { mainFrame.setSize( Math.max(mainFrame.getSize().width, 400), Math.max(mainFrame.getSize().height, 180)); } // center frame mainFrame.setLocation( mainFrame.getToolkit().getScreenSize().width / 2 - mainFrame.getSize().width / 2, mainFrame.getToolkit().getScreenSize().height / 2 - mainFrame.getSize().height / 2); mainFrame.setVisible(true); // display settings frame on first start if (Settings.isFirstStart()) { settingsFrame.setVisible(true); settingsFrame.toFront(); settingsFrame.requestFocus(); } }
public BaseballController() { // Connect to Database try { dataBase = new DBWrapper(); } catch (SQLException e) { e.printStackTrace(); } screen = new JFrame("Math Baseball"); screen.setExtendedState(Frame.MAXIMIZED_BOTH); screen.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); inputManager = new InputManager(screen); createGameActions(); loginPanel = new BackGroundPanel(); loginPanel.setPreferredSize(screen.getSize()); loginPanel.setOpaque(false); loginPanel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; uNameField = new JTextField(); TextPrompt uText = new TextPrompt("Username", uNameField, TextPrompt.Show.FOCUS_LOST); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 1; loginPanel.add(uNameField, constraints); pWordField = new JPasswordField(); TextPrompt pText = new TextPrompt("Password", pWordField, TextPrompt.Show.FOCUS_LOST); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 2; loginPanel.add(pWordField, constraints); isTeacher = new JRadioButton("Teacher"); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 3; loginPanel.add(isTeacher, constraints); loginButton = createButton("loginButton", "To Login"); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 4; loginPanel.add(loginButton, constraints); registerButton = new JButton("Register"); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 5; constraints.anchor = GridBagConstraints.PAGE_END; loginPanel.add(registerButton, constraints); Container contentPane = screen.getContentPane(); // make sure the content pane is transparent if (contentPane instanceof JComponent) { ((JComponent) contentPane).setOpaque(false); } // add components to the screen's content pane contentPane.add(loginPanel); screen.setVisible(true); screen.validate(); // screen.repaint(); // add listeners isTeacher.addActionListener(this); loginButton.addActionListener(this); registerButton.addActionListener(this); }
public Dimension getSize() { return jFrame.getSize(); }
/** ******************************* SIZE COMPUTATION ******************************* */ protected void setSizes(JFrame f) { Dimension panelDimensions = f.getSize(); computeFirmSizes(panelDimensions); computeMarketsSize(panelDimensions); computeWorkersSizes(panelDimensions); }
// // Build installer window // public static void showInstallerWindow() { _installerFrame = new JFrame(Config.getWindowTitle()); Container cont = _installerFrame.getContentPane(); cont.setLayout(new BorderLayout()); // North pane Box topPane = new Box(BoxLayout.X_AXIS); JLabel title = new JLabel(Config.getWindowHeading()); Font titleFont = new Font("SansSerif", Font.BOLD, 22); title.setFont(titleFont); title.setForeground(Color.black); // Create Sun logo URL urlLogo = Main.class.getResource(Config.getWindowLogo()); Image img = Toolkit.getDefaultToolkit().getImage(urlLogo); MediaTracker md = new MediaTracker(_installerFrame); md.addImage(img, 0); try { md.waitForAll(); } catch (Exception ioe) { Config.trace(ioe.toString()); } if (md.isErrorID(0)) Config.trace("Error loading image"); Icon sunLogo = new ImageIcon(img); JLabel logoLabel = new JLabel(sunLogo); logoLabel.setOpaque(true); topPane.add(topPane.createHorizontalStrut(5)); topPane.add(title); topPane.add(topPane.createHorizontalGlue()); topPane.add(logoLabel); topPane.add(topPane.createHorizontalStrut(5)); // West Pane Box westPane = new Box(BoxLayout.X_AXIS); westPane.add(westPane.createHorizontalStrut(10)); // South Pane Box bottomPane = new Box(BoxLayout.X_AXIS); bottomPane.add(bottomPane.createHorizontalGlue()); JButton abortButton = new JButton(Config.getWindowAbortButton()); abortButton.setMnemonic(Config.getWindowAbortMnemonic()); bottomPane.add(abortButton); bottomPane.add(bottomPane.createHorizontalGlue()); bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); // Center Pane Box centerPane = new Box(BoxLayout.Y_AXIS); JLabel hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); _stepLabels = new JLabel[5]; for (int i = 0; i < _stepLabels.length; i++) { _stepLabels[i] = new JLabel(Config.getWindowStep(i)); _stepLabels[i].setEnabled(false); centerPane.add(_stepLabels[i]); // install label's length will expand,so set a longer size. if (i == STEP_INSTALL) { Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize(); _stepLabels[i].setPreferredSize(dim); } } hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); // Setup box layout cont.add(topPane, "North"); cont.add(westPane, "West"); cont.add(bottomPane, "South"); cont.add(centerPane, "Center"); _installerFrame.pack(); Dimension dim = _installerFrame.getSize(); // hard code to ensure title is completely visible on Sol/lin. if (dim.width < 400) { dim.width = 400; _installerFrame.setSize(dim); } Rectangle size = _installerFrame.getBounds(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); size.width = Math.min(screenSize.width, size.width); size.height = Math.min(screenSize.height, size.height); // Put window at 1/4, 1/4 of screen resoluion _installerFrame.setBounds( (screenSize.width - size.width) / 4, (screenSize.height - size.height) / 4, size.width, size.height); // Setup event listners _installerFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { installFailed("Window closed", null); } }); abortButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { installFailed("Abort pressed", null); } }); // Show window _installerFrame.show(); }
void main() { CommonSwing.setDefaultColor(); fMain = new JFrame("HSQL Database Manager"); // (ulrivo): An actual icon. fMain.getContentPane().add(createToolBar(), "North"); fMain.setIconImage(CommonSwing.getIcon()); fMain.addWindowListener(this); JMenuBar bar = new JMenuBar(); // used shortcuts: CERGTSIUDOLM String fitems[] = { "-Connect...", "--", "-Open Script...", "-Save Script...", "-Save Result...", "--", "-Exit" }; addMenu(bar, "File", fitems); String vitems[] = {"RRefresh Tree", "--", "GResults in Grid", "TResults in Text"}; addMenu(bar, "View", vitems); String sitems[] = { "SSELECT", "IINSERT", "UUPDATE", "DDELETE", "---", "-CREATE TABLE", "-DROP TABLE", "-CREATE INDEX", "-DROP INDEX", "--", "-CHECKPOINT", "-SCRIPT", "-SET", "-SHUTDOWN", "--", "-Test Script" }; addMenu(bar, "Command", sitems); mRecent = new JMenu("Recent"); bar.add(mRecent); String soptions[] = { "-AutoCommit on", "-AutoCommit off", "OCommit", "LRollback", "--", "-Disable MaxRows", "-Set MaxRows to 100", "--", "-Logging on", "-Logging off", "--", "-Insert test data" }; addMenu(bar, "Options", soptions); String stools[] = {"-Dump", "-Restore", "-Transfer"}; addMenu(bar, "Tools", stools); fMain.setJMenuBar(bar); initGUI(); sRecent = new String[iMaxRecent]; Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = fMain.getSize(); // (ulrivo): full size on screen with less than 640 width if (d.width >= 640) { fMain.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2); } else { fMain.setLocation(0, 0); fMain.setSize(d); } fMain.show(); // (ulrivo): load query from command line if (defScript != null) { if (defDirectory != null) { defScript = defDirectory + File.separator + defScript; } // if insert stmet is thousands of records...skip showing it // as text. Too huge. StringBuffer buf = new StringBuffer(); ifHuge = DatabaseManagerCommon.readFile(defScript); if (4096 <= ifHuge.length()) { buf.append("This huge file cannot be edited. Please execute\n"); txtCommand.setText(buf.toString()); } else { txtCommand.setText(ifHuge); } } txtCommand.requestFocus(); }