/** * Show the given message in a dialog box or independent window, depending on whether the source * component is contained in a Frame or not. * * @param c The Controller that calls this method, or null if it is not called by a Controller. * (The Controller, if any, will be notified when the error message is cleared.) * @param message The message to display. */ public void setErrorMessage(Controller c, String message) { if (popup != null) clearErrorMessage(); if (message == null) return; errorSource = c; errorMessage = message; Component parent = source; while (parent != null && !(parent instanceof Frame)) parent = parent.getParent(); if (parent != null) popup = new Dialog((Frame) parent, "Error Message", true); // modal dialog else popup = new Frame("Error Message"); // independent window popup.setBackground(Color.white); popup.add(new MC(message), BorderLayout.CENTER); Panel buttonBar = new Panel(); buttonBar.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10)); Button OK = new Button(" OK "); OK.addActionListener(this); buttonBar.add(OK); popup.add(buttonBar, BorderLayout.SOUTH); popup.pack(); if (parent == null) popup.setLocation(100, 80); else popup.setLocation(parent.getLocation().x + 50, parent.getLocation().y + 30); popup.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent evt) { popup.dispose(); } }); popup.show(); // make the dialog visible. }
/** * @throws NoSuchRecordFieldException * @throws IOException */ @Test public void testComputedField() throws NoSuchRecordFieldException, IOException { List<Panel> panelList = database.getPanels(); for (Panel panel : panelList) { List<Field> fieldList = panel.getFields(); for (Iterator<Record> recordIterator = panel.recordIterator(); recordIterator.hasNext(); ) { Record record = recordIterator.next(); Iterator<Field> fieldIterator = fieldList.iterator(); while (fieldIterator.hasNext()) { Field field = fieldIterator.next(); if (field.getInitialization() != null) { assertTrue(field.getInitialization() != null); if (field.isComputedField()) { assertTrue(field.isComputedField()); assertTrue(record.getValueAsString(field.getNumber()) == null); } else { assertFalse(field.isComputedField()); assertTrue(record.getValueAsString(field.getNumber()) != null); } } else { if (field.getLink() == null || field.getLink().getType() == LinkType.DATA_LINK) { assertTrue(record.getValueAsString(field.getNumber()) != null); } } } } } }
@Test public void comparatorTest() { final LayoutPanel layout = ContextUtil.getDefaultPanel(TabbedLayoutPanel.class); Assert.assertNotNull(layout); for (int i = 1; i <= 5; i++) { final Panel content = ContextUtil.getDefaultPanel(MutableEntityViewPanel.class); content.setParent(layout); content.setIndex(i); Assert.assertEquals(layout, content.getParent()); } Assert.assertEquals(5, layout.getSubpanels().size()); final Panel[] array = layout.getSubpanels().toArray(new Panel[] {}); for (int i = 0; i <= 4; i++) { array[i].setIndex(4 - i); } layout.getSubpanels().sort(); int i = 4; for (final Panel panel : layout.getSubpanels()) { Assert.assertEquals(panel, array[i]); i--; } }
public CollageList() { super(); actionComponent = new Button(); Panel toolBar; setLayout(new BorderLayout()); // ggHScroll = new Scrollbar( Scrollbar.HORIZONTAL, 0, 0x8000, 0, 0x8000 ); ggVScroll = new Scrollbar(Scrollbar.VERTICAL, 0, 0x8000, 0, 0x8000); // ggHScroll.addAdjustmentListener( ggCurve ); ggVScroll.addAdjustmentListener(this); toolBar = new Panel(); toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 2)); ggAdd = new JButton(" Add "); ggDel = new JButton(" Delete "); ggDup = new JButton(" Duplicate "); ggAdd.addActionListener(this); ggDel.addActionListener(this); ggDup.addActionListener(this); toolBar.add(ggAdd); toolBar.add(ggDel); toolBar.add(ggDup); add(toolBar, BorderLayout.NORTH); // add( ggHScroll, BorderLayout.SOUTH ); add(ggVScroll, BorderLayout.EAST); add(new CollageCanvas(this), BorderLayout.CENTER); // add( ggCurve, BorderLayout.CENTER ); }
private void updateDebugPanelState(String result, boolean debug, boolean test) { result = result == null ? "nothing" : result; List<Component> componentList = Arrays.asList(getComponents()); if (!componentList.contains(p_debug)) { choice = new Label(String.format("Your choice is: %s", result)); isDebug = new Label(String.format("Debug mode: %b", debug)); isTest = new Label(String.format("Test mode: %b", test)); GridBagLayout layout = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); layout.setConstraints(choice, constraints); constraints.gridy = 1; layout.setConstraints(isDebug, constraints); constraints.gridy = 2; layout.setConstraints(isTest, constraints); p_debug.setLayout(layout); p_debug.add(choice); p_debug.add(isDebug); p_debug.add(isTest); add(p_debug, BorderLayout.SOUTH); } else { choice.setText(String.format("Your choice is: %s", result)); isDebug.setText(String.format("Debug mode: %b", debug)); isTest.setText(String.format("Test mode: %b", test)); } }
public void layoutContainer(Container obj) { Rectangle r = obj.bounds(); int width = r.width - TF_LEFT + TF_RIGHT; if (width < 0) return; int height = r.height - TF_TOP + TF_BOTTOM; if (height < 0) return; int col = TF_LEFT; int row = 0; if (iTabsPosition == TOP) row = TF_TOP; else row = TF_TOP - TF_BTN_HEIGHT; oobj.move(col + 1, row + 1); // oobj.move(0,0); oobj.resize(width - 3, height - 3); if (iTabsPosition == TOP) { dbLeft.move(r.width - 33 + TF_RIGHT, TF_TOP - 16); dbRight.move(r.width - 16 + TF_RIGHT, TF_TOP - 16); dbLeft.resize(16, 15); dbRight.resize(16, 15); } else { dbLeft.move(r.width - 33 + TF_RIGHT, r.height + TF_BOTTOM - TF_BTN_HEIGHT); dbRight.move(r.width - 16 + TF_RIGHT, r.height + TF_BOTTOM - TF_BTN_HEIGHT); dbLeft.resize(16, 15); dbRight.resize(16, 15); } repaint(); }
/** * Adds a radio button group. * * @param label group label (or null) * @param items radio button labels * @param rows number of rows * @param columns number of columns * @param defaultItem button initially selected */ public void addRadioButtonGroup( String label, String[] items, int rows, int columns, String defaultItem) { Panel panel = new Panel(); int n = items.length; panel.setLayout(new GridLayout(rows, columns, 0, 0)); CheckboxGroup cg = new CheckboxGroup(); for (int i = 0; i < n; i++) { Checkbox cb = new Checkbox(items[i], cg, items[i].equals(defaultItem)); cb.addItemListener(this); panel.add(cb); } if (radioButtonGroups == null) radioButtonGroups = new Vector(); radioButtonGroups.addElement(cg); Insets insets = getInsets(5, 10, 0, 0); if (label == null || label.equals("")) { label = "rbg" + radioButtonGroups.size(); insets.top += 5; } else { setInsets(10, insets.left, 0); addMessage(label); insets.top = 2; insets.left += 10; } c.gridx = 0; c.gridy = y; c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(insets.top, insets.left, 0, 0); grid.setConstraints(panel, c); add(panel); if (Recorder.record || macro) saveLabel(cg, label); y++; }
public Ticker(Container c) { b.addActionListener(new ToggleL()); Panel p = new Panel(); p.add(t); p.add(b); c.add(p); }
public void run() { try { root.setName("test root"); p.getExplorerManager().setRootContext(root); p.add(BorderLayout.CENTER, btv); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(BorderLayout.CENTER, p); f.setVisible(true); ab.set(true); while (ab.get() == true) { try { Thread.sleep(50); } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } } Node[] nodes = children.getNodes(); try { p.getExplorerManager().setSelectedNodes(new Node[] {nodes[2]}); } catch (PropertyVetoException ex) { Exceptions.printStackTrace(ex); } TreePath[] paths = tree.getSelectionPaths(); ok = true; } finally { ab.set(true); } }
public GetDataFrame(PlayableApplet anApplet, AppletRecorder ar) { // call base class constructor super("Get Student Data"); theApplet = anApplet; theAR = ar; resize(212, 206); start = new Button("Start"); step = new Button("Step"); step.disable(); close = new Button("Cancel"); makeSessionList(); buttonsPanel = new Panel(); buttonsPanel.add("West", start); buttonsPanel.add("Center", step); buttonsPanel.add("East", close); sessionsPanel = new Panel(); sessionsPanel.resize(150, 150); sessionsPanel.add("Center", sessionList); add("North", new Label("Select a Session:", Label.LEFT)); add("Center", sessionsPanel); add("South", buttonsPanel); show(); }
public void init() { setLayout(new BorderLayout()); single.add("0"); single.add("1"); single.add("2"); single.add("3"); single.add("4"); single.add("5"); single.add("6"); single.add("7"); single.add("8"); multiple.add("0"); multiple.add("1"); multiple.add("2"); multiple.add("3"); multiple.add("4"); multiple.add("5"); multiple.add("6"); multiple.add("7"); multiple.add("8"); single.addKeyListener(this); single.addItemListener(this); single.addFocusListener(this); p1.add(single); add("North", p1); multiple.addKeyListener(this); multiple.addItemListener(this); multiple.addFocusListener(this); p2.add(multiple); add("South", p2); } // End init()
/** * Constructor called from getInstance() * * @param model - A model is needed so that we can observe it and respond to its changes */ private CelsiusView(TemperatureModel model) { // Set up fields this.model = model; this.upButton = new JButton("Raise"); this.downButton = new JButton("Lower"); // Add an observer to the model model.addObserver(this); // Allows us to close the window this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // Make the text to display // Edit this for CelsiusView temp = new JLabel("Model Temperature in Celcius: " + model.getC(), SwingConstants.CENTER); this.add(temp); // Make the buttons Panel buttons = new Panel(); buttons.add(upButton); buttons.add(downButton); this.add("South", buttons); this.setSize(400, 100); setLocationRelativeTo(null); }
protected void renderPanel(Panel panel, boolean canEditPanel) { if (!isPanelOk(panel)) return; setAttribute("panel", panel); setAttribute("recommendedWidth", panelRecommendedWidth + "%"); renderFragment("panelOutputStart"); if (panel.isPaintTitle() || panel.getPanelSession().isMinimized() || (userAdmin) || (panel.getProvider().getDriver().supportsEditMode(panel) && canEditPanel)) { setAttribute("panel", panel); setAttribute("administratorMode", userAdmin); setAttribute( "panelTitle", StringEscapeUtils.ESCAPE_HTML4.translate(getLocalizedValue(panel.getTitle()))); setAttribute("recommendedWidth", panelRecommendedWidth + "%"); setAttribute("editMode", panel.getPanelSession().isEditMode()); renderFragment("panelContentWithMenu"); } else { setAttribute("panel", panel); setAttribute("recommendedWidth", panelRecommendedWidth + "%"); renderFragment("panelContentWithoutMenu"); } setAttribute("panel", panel); renderFragment("panelOutputEnd"); }
private List<Panel> getRegionPanels() { Panel[] allPanels = currentSectionRegion.getPanels(); List<Panel> panels = new ArrayList<Panel>(); boolean onlyOnePanel = false; // When a panel is maximized in region, only show it. for (int i = 0; i < allPanels.length; i++) { Panel panel = allPanels[i]; PanelSession status = panel.getPanelSession(); if (status.isMaximizedInRegion()) { PanelPermission viewPerm = PanelPermission.newInstance(panel, PanelPermission.ACTION_VIEW); boolean canViewPanel = getUserStatus().hasPermission(viewPerm); if (canViewPanel) { panels.add(panel); onlyOnePanel = true; break; } } } if (!onlyOnePanel) for (int i = 0; i < allPanels.length; i++) { Panel panel = allPanels[i]; PanelPermission viewPerm = PanelPermission.newInstance(panel, PanelPermission.ACTION_VIEW); boolean canViewPanel = getUserStatus().hasPermission(viewPerm); if (canViewPanel) { panels.add(panel); } } return panels; }
public void init() { // a grid to layout the screen nicely JLabel title = new JLabel("THE GAME OF NIM!"); title.setFont(new Font("Times New Roman", Font.PLAIN, 48)); Panel p = new Panel(); resize(500, 100); // declare a new array of buttons a = new JButton[row]; // initialize each of the buttons in the array // with an empty label for (int nNum = 0; nNum < row; nNum++) { a[nNum] = new JButton("8"); p.add(a[nNum]); // each button will have an action listener a[nNum].addActionListener(this); a[nNum].setBackground(Color.yellow); // each button will send a message with its number a[nNum].setActionCommand("" + nNum); } name = JOptionPane.showInputDialog("Enter name Player 1: "); name2 = JOptionPane.showInputDialog("Enter name Player 2: "); JButton reset = new JButton("Reset"); reset.addActionListener(this); reset.setActionCommand("re"); status = new JLabel("Welcome! The player to remove the final stones is the loser!"); add(title); add(status); add(p); add(reset); }
/** Create the tag frame. */ TextFrame(int x, int y, String title, String text) { setTitle(title); TextArea txt = new TextArea(20, 60); txt.setText(text); txt.setEditable(false); add("Center", txt); Panel p = new Panel(); add("South", p); Button b = new Button(amh.getMessage("button.dismiss", "Dismiss")); p.add(b); class ActionEventListener implements ActionListener { public void actionPerformed(ActionEvent evt) { dispose(); } } b.addActionListener(new ActionEventListener()); pack(); move(x, y); setVisible(true); WindowListener windowEventListener = new WindowAdapter() { public void windowClosing(WindowEvent evt) { dispose(); } }; addWindowListener(windowEventListener); }
/** *********************************************************************** */ private static void createAndShowGUI() { JFrame.setDefaultLookAndFeelDecorated(true); // give JFrame nice decorations JFrame frame = new JFrame("Java GUI"); // create the JFrame frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); // set up the JFrame to end the program when it closes Container c = frame.getContentPane(); c.setLayout(new BorderLayout()); ColorBars drawingPanel = new ColorBars(); // set up the panel to draw in drawingPanel.setBackground(Color.BLACK); // the the background to black drawingPanel.btnDraw = new JButton("Click me"); // instantiate a swing button drawingPanel.btnDraw.addActionListener(drawingPanel); // register the panel with the button drawingPanel.btnClear = new JButton("Clear Screen"); drawingPanel.btnClear.addActionListener(drawingPanel); Panel buttonPanel = new Panel(); // instantiate the panel for buttons buttonPanel.add(drawingPanel.btnDraw); // add the swing button the the button panel buttonPanel.add(drawingPanel.btnClear); c.add( drawingPanel, BorderLayout.CENTER); // add the drawing panel to the frame (take up the entire frame) c.add(buttonPanel, BorderLayout.SOUTH); // add the button panel to the bottom of the frame frame.setExtendedState(JFrame.MAXIMIZED_BOTH); // set the window to maximized frame.setSize(600, 400); // set the frame size (in case user un-maximizes frame.setVisible(true); // display the frame }
void action() { Panel p = new Panel(); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); but1 = new Button("버튼-1"); but2 = new Button("버튼-2"); // 버튼에 감지 기능 추가 but1.addActionListener(this); but2.addActionListener(this); p.add(but1); p.add(but2); add(p, "North"); tf = new TextField(); add(tf, "South"); setSize(150, 100); setVisible(true); }
public Newt() { addWindowListener(new WindowEventHandler()); setTitle("Newt"); setLayout(new BorderLayout()); // create a panel with the fractal image contained in it Panel p = new Panel(new FlowLayout()); fractalGenerator = new FractalGenerator( DEFAULT_MINX, DEFAULT_MAXX, DEFAULT_MINY, DEFAULT_MAXY, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_MAX_ITERATIONS); fractalGenerator.setFractal(new MandelbrotSet()); p.add(fractalGenerator); add("Center", p); setMenuBar(new NewtMenuBar()); pack(); setVisible(true); fractalGenerator.generateImage(); }
buildInvite() { Frame f = new Frame(); Label l = new Label("Hoy hay Development Party: Java and Python are our guests"); Button b = new Button("Python Rocks!!!"); Button c = new Button("Java Rules!!!"); Panel p = new Panel(); p.add(l); }
private void addEnterTwoValues(Panel p, String one, String two) { p.add(new Label("Enter value for Dimension " + one)); TextField dim1 = new TextField(8); p.add(dim1); p.add(new Label("Enter value for Dimension " + two)); TextField dim2 = new TextField(8); p.add(dim2); }
// aqui pasa todo para crear una nueva ventana para poner las animaciones dentro. public Ventana() { setExtendedState(MAXIMIZED_BOTH); setUndecorated(true); setDefaultCloseOperation(EXIT_ON_CLOSE); Panel miPanel = new Panel(); setContentPane(miPanel); setVisible(true); miPanel.requestFocus(); }
public AddLayerDialog(String title, Document document) { super(title); this.document = document; Panel buttons = new Panel(); buttons.add("East", ok = new Button("OK")); buttons.add("West", cancel = new Button("Cancel")); // add("Center", text = new TextArea()); add("South", buttons); }
/** This is called in the unhappy event of there being errors. */ public static void showBuilderErrors( BuilderResult results, Panel buildResults, ClientFactory clientFactory) { buildResults.clear(); BuildPackageErrorsSimpleTable errorsTable = new BuildPackageErrorsSimpleTable(clientFactory); errorsTable.setRowData(results.getLines()); errorsTable.setRowCount(results.getLines().size()); buildResults.add(errorsTable); }
/** * Adds a group of checkboxs using a grid layout. * * @param rows the number of rows * @param columns the number of columns * @param labels the labels * @param defaultValues the initial states * @param headings the column headings Example: * http://imagej.nih.gov/ij/plugins/multi-column-dialog/index.html */ public void addCheckboxGroup( int rows, int columns, String[] labels, boolean[] defaultValues, String[] headings) { Panel panel = new Panel(); int nRows = headings != null ? rows + 1 : rows; panel.setLayout(new GridLayout(nRows, columns, 6, 0)); int startCBIndex = cbIndex; if (checkbox == null) checkbox = new Vector(12); if (headings != null) { Font font = new Font("SansSerif", Font.BOLD, 12); for (int i = 0; i < columns; i++) { if (i > headings.length - 1 || headings[i] == null) panel.add(new Label("")); else { Label label = new Label(headings[i]); label.setFont(font); panel.add(label); } } } int i1 = 0; int[] index = new int[labels.length]; for (int row = 0; row < rows; row++) { for (int col = 0; col < columns; col++) { int i2 = col * rows + row; if (i2 >= labels.length) break; index[i1] = i2; String label = labels[i1]; if (label == null || label.length() == 0) { Label lbl = new Label(""); panel.add(lbl); i1++; continue; } if (label.indexOf('_') != -1) label = label.replace('_', ' '); Checkbox cb = new Checkbox(label); checkbox.addElement(cb); cb.setState(defaultValues[i1]); cb.addItemListener(this); if (Recorder.record || macro) saveLabel(cb, labels[i1]); if (IJ.isLinux()) { Panel panel2 = new Panel(); panel2.setLayout(new BorderLayout()); panel2.add("West", cb); panel.add(panel2); } else panel.add(cb); i1++; } } c.gridx = 0; c.gridy = y; c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.insets = getInsets(10, 0, 0, 0); grid.setConstraints(panel, c); add(panel); y++; }
public void buildChooser() { Panel panel = new Panel(); panel.setLayout(new GridLayout()); for (int i = 1; i <= 3; i++) { for (int x = 1; x <= 2; x++) { panel.add(addButton(i * x + "", Color.yellow)); } } add(panel); }
/** Method declaration */ private void initGUI() { Panel pQuery = new Panel(); Panel pCommand = new Panel(); pResult = new Panel(); pQuery.setLayout(new BorderLayout()); pCommand.setLayout(new BorderLayout()); pResult.setLayout(new BorderLayout()); Font fFont = new Font("Dialog", Font.PLAIN, 12); txtCommand = new TextArea(5, 40); txtCommand.addKeyListener(this); txtResult = new TextArea(20, 40); txtCommand.setFont(fFont); txtResult.setFont(new Font("Courier", Font.PLAIN, 12)); butExecute = new Button("Execute"); butClear = new Button("Clear"); butExecute.addActionListener(this); butClear.addActionListener(this); pCommand.add("East", butExecute); pCommand.add("West", butClear); pCommand.add("Center", txtCommand); gResult = new Grid(); setLayout(new BorderLayout()); pResult.add("Center", gResult); pQuery.add("North", pCommand); pQuery.add("Center", pResult); fMain.add("Center", pQuery); tTree = new Tree(); // (ulrivo): screen with less than 640 width Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); if (d.width >= 640) { tTree.setMinimumSize(new Dimension(200, 100)); } else { tTree.setMinimumSize(new Dimension(80, 100)); } gResult.setMinimumSize(new Dimension(200, 300)); fMain.add("West", tTree); doLayout(); fMain.pack(); }
Component createComponent(Component owner) { Panel component = new MediumWeightComponent(); rootPane = new JRootPane(); // NOTE: this uses setOpaque vs LookAndFeel.installProperty as // there is NO reason for the RootPane not to be opaque. For // painting to work the contentPane must be opaque, therefor the // RootPane can also be opaque. rootPane.setOpaque(true); component.add(rootPane, BorderLayout.CENTER); return component; }
private Dimension getSize(Container obj, boolean max) { int width = TF_LEFT - TF_RIGHT; int height = TF_TOP - TF_BOTTOM; int col = TF_LEFT; int row = 0; if (iTabsPosition == TOP) row = TF_TOP; else row = TF_TOP - TF_BTN_HEIGHT; Dimension d = max ? oobj.preferredSize() : oobj.minimumSize(); return new Dimension(d.width + width, d.height + height); }
public UserSelect() { loginInfo = new Label(""); loginInfo.addStyleName("error-font"); loginInfo.addStyleName("margin15"); loginInfo.addStyleName("margin-top40"); loginInfo.setVisible(false); selected = null; loginField = new PasswordField(""); loginField.setWidth("200px"); loginField.addStyleName("margin15"); loginField.addStyleName("margin-bot40"); loginBut = new Button("login"); loginBut.addStyleName("margin15"); loginBut.addClickListener( e -> { if (loginField.getValue().equals(selected.getPassword())) { hidePass(); Globals.user = selected; Globals.root.changeScreen(Globals.user); } else { loginInfo.setVisible(true); loginInfo.setValue("Wrong password"); loginField.setValue(""); } }); loginBox = new HorizontalLayout(); loginBox.addStyleName("popup-box"); loginBox.addComponents(loginField, loginBut, loginInfo); loginBox.setComponentAlignment(loginField, Alignment.MIDDLE_LEFT); loginBox.setComponentAlignment(loginBut, Alignment.MIDDLE_CENTER); loginBox.setComponentAlignment(loginField, Alignment.MIDDLE_RIGHT); loginBox.setVisible(false); userIcon = new ThemeResource("icons/user.png"); users = Globals.control.usersData(); vbox = new VerticalLayout(); // vbox.setSizeUndefined(); vbox.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); Panel p = new Panel(); p.setSizeFull(); p.setContent(vbox); // vbox.addStyleName("border-l-r"); this.addComponent(p, "left: 25%; right: 25%; top: 15px"); this.addComponent(loginBox, "left: 25%; right: 25%; top: 40%"); this.addLayoutClickListener( e -> { if (!loginBox.isVisible()) return; System.out.println(e.getClickedComponent()); if (e.getClickedComponent() == null || e.getClickedComponent().equals(vbox)) hidePass(); }); }