private JPanel getUpdatePanel() { if (updatePanel == null) { updatePanel = new JPanel(new GridBagLayout()); updatePanel.setBorder(new EmptyBorder(0, 30, 0, 5)); final GridBagConstraints constraints = new GridBagConstraints(); constraints.insets = new Insets(0, 5, 5, 5); constraints.weighty = 0; constraints.weightx = 0; constraints.anchor = GridBagConstraints.NORTHWEST; constraints.gridy = 0; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.weightx = 0.5; updatePanel.add(minimumIntervalLabel, constraints); constraints.fill = GridBagConstraints.NONE; constraints.gridx = 1; constraints.weightx = 1; updatePanel.add(minimumIntervalTextField, constraints); constraints.insets = new Insets(0, 5, 0, 5); // we have a bottom inset in the containing layout! constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy++; constraints.weightx = 0.5; updatePanel.add(concurrentUpdatesLabel, constraints); constraints.fill = GridBagConstraints.NONE; constraints.gridx = 1; constraints.weightx = 1; updatePanel.add(concurrentUpdatesTextField, constraints); } return updatePanel; }
/** * public MutableStatusBar(String s1, String s2, String s3) { super(); status_1 = new JLabel(s1); * status_2 = new JLabel(s2); status_3 = new JLabel(s3); this.init(); }. */ protected void init() { this.setLayout(new GridBagLayout()); this.setBorder(BorderFactory.createEmptyBorder(3, 2, 1, 1)); final GridBagConstraints constraints = new GridBagConstraints(); // status_1.setHorizontalAlignment(JLabel.CENTER); status_1.setBorder( new CompoundBorder( new SoftBevelBorder(SoftBevelBorder.LOWERED), new EmptyBorder(0, 2, 0, 2))); status_1.setPreferredSize(new Dimension(180, 16)); status_2.setBorder( new CompoundBorder( new SoftBevelBorder(SoftBevelBorder.LOWERED), new EmptyBorder(0, 2, 0, 2))); status_2.setPreferredSize(new Dimension(200, 16)); status_3.setBorder( new CompoundBorder( new SoftBevelBorder(SoftBevelBorder.LOWERED), new EmptyBorder(0, 2, 0, 2))); status_3.setPreferredSize(new Dimension(300, 16)); greenStatusIcon = new MutableImageLabel(resource.getIcon("green_off.gif"), resource.getIcon("green_on.gif")); greenStatusIcon.setBorder(new EmptyBorder(2, 2, 2, 1)); redStatusIcon = new MutableImageLabel(resource.getIcon("red_off.gif"), resource.getIcon("red_on.gif")); redStatusIcon.setBorder(new EmptyBorder(2, 1, 2, 3)); // ===================================================================== constraints.insets = new Insets(0, 0, 0, 4); constraints.anchor = GridBagConstraints.EAST; constraints.fill = GridBagConstraints.VERTICAL; constraints.weightx = 1.0; constraints.weighty = 1.0; constraints.gridx = 0; constraints.gridy = 0; constraints.gridwidth = 1; constraints.gridheight = 1; this.add(status_1, constraints); constraints.weightx = 0.0; constraints.gridx++; this.add(status_2, constraints); constraints.gridx = 2; this.add(status_3, constraints); constraints.gridx++; if (greenStatusIcon != null) { this.add(greenStatusIcon, constraints); } constraints.insets = new Insets(0, 0, 0, 0); constraints.gridx++; if (redStatusIcon != null) { this.add(redStatusIcon, constraints); } }
public void addForDisplay(CTalkativeTextPane pane, LabelPair<String, String> lp) { GridBagLayout gridbag = (GridBagLayout) getLayout(); labelPair = lp; label = new JLabel(labelPair.getSingular(), JLabel.LEFT); pane.getDocument().addDocumentListener(this); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.1; c.weighty = 0.1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 20, 0, 00); gridbag.setConstraints(pane, c); add(pane); c = new GridBagConstraints(); c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.1; c.weighty = 0.1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 20); gridbag.setConstraints(label, c); add(label); JPanel filler = new JPanel(); filler.setBackground(white); c = new GridBagConstraints(); c.gridx = 2; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.8; c.weighty = 0.8; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.LINE_END; gridbag.setConstraints(filler, c); add(filler); filler = null; c = null; }
protected GridBagConstraints createConstraints(int x, int y) { GridBagConstraints c = new GridBagConstraints(); c.gridx = x; c.gridy = y; c.gridwidth = 2; c.gridheight = 1; c.ipadx = 1; c.weightx = 0.5; c.weighty = 0.5; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; return c; }
public SyntaxTest() { JFrame frame = new JFrame(); frame.setSize(300, 300); JEditorPane editor = new JEditorPane(); DefaultSyntaxKit.initKit(); editor.setContentType("text/banking"); frame.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; c.weighty = 1.0; c.fill = GridBagConstraints.BOTH; frame.add(editor, c); frame.pack(); frame.setVisible(true); }
private static JPanel createTextFieldAndListPanel( String label, JTextField textField, JList list) { GridBagLayout layout = new GridBagLayout(); JPanel panel = new JPanel(layout); GridBagConstraints cons = new GridBagConstraints(); cons.gridx = cons.gridy = 0; cons.gridwidth = cons.gridheight = 1; cons.fill = GridBagConstraints.BOTH; cons.weightx = 1.0f; JLabel _label = new JLabel(jEdit.getProperty(label)); layout.setConstraints(_label, cons); panel.add(_label); cons.gridy = 1; Component vs = Box.createVerticalStrut(6); layout.setConstraints(vs, cons); panel.add(vs); cons.gridy = 2; layout.setConstraints(textField, cons); panel.add(textField); cons.gridy = 3; vs = Box.createVerticalStrut(6); layout.setConstraints(vs, cons); panel.add(vs); cons.gridy = 4; cons.gridheight = GridBagConstraints.REMAINDER; cons.weighty = 1.0f; JScrollPane scroller = new JScrollPane(list); layout.setConstraints(scroller, cons); panel.add(scroller); return panel; }
private Connector() { setLayout(new GridBagLayout()); // setBorder (new EmptyBorder (8, 8, 8, 8)); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(0, 0, 3, 3); c.anchor = GridBagConstraints.WEST; add(new JLabel(bundle.getString("CTL_HostName")), c); tfHost = new JTextField(host, 25); c = new GridBagConstraints(); c.gridwidth = 0; c.insets = new Insets(0, 3, 3, 0); c.fill = java.awt.GridBagConstraints.HORIZONTAL; c.weightx = 1.0; add(tfHost, c); c = new GridBagConstraints(); c.insets = new Insets(3, 0, 0, 3); c.anchor = GridBagConstraints.WEST; add(new JLabel(bundle.getString("CTL_Password")), c); tfPassword = new JTextField(25); c = new GridBagConstraints(); c.gridwidth = 0; c.fill = java.awt.GridBagConstraints.HORIZONTAL; c.weightx = 1.0; c.insets = new Insets(3, 3, 0, 0); add(tfPassword, c); c = new GridBagConstraints(); c.fill = java.awt.GridBagConstraints.BOTH; c.weighty = 1.0; JPanel p = new JPanel(); p.setPreferredSize(new Dimension(1, 1)); add(p, c); }
protected void populateDialog(JDialog dlg) { dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dlg.setResizable(false); dlg.setSize(new Dimension(350, 135)); dlg.setTitle("New TurboVNC Connection"); dlg.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { if (VncViewer.nViewers == 1) { if (cc.viewer instanceof VncViewer) { ((VncViewer) cc.viewer).exit(1); } } else { ret = false; endDialog(); } } }); dlg.getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.LINE_START; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = 1; gbc.insets = new Insets(0, 0, 0, 0); gbc.ipadx = 0; gbc.ipady = 0; gbc.weightx = 1; gbc.weighty = 1; dlg.getContentPane().add(topPanel, gbc); dlg.getContentPane().add(buttonPanel); dlg.pack(); }
/** * The consturctor Constructor instantiates all the panels, convertible value instance, and the * frame. And adds the panels to the frame. And sets a proper size for the frame. */ public HappyHackingConverter() { CFrame frame = new CFrame(); frame.setBackground(white); ConvertibleValue temperatures = new ConvertibleValue(); ConvertibleValue distances = new ConvertibleValue(); ConvertibleValue weights = new ConvertibleValue(); GridBagLayout leftSideLayout = new GridBagLayout(); JPanel leftSide = new JPanel(leftSideLayout); leftSide.setBackground(white); GridBagLayout rightSideLayout = new GridBagLayout(); JPanel rightSide = new JPanel(rightSideLayout); rightSide.setBackground(white); GridBagConstraints metricTemperatureConstraints = new GridBagConstraints(); metricTemperatureConstraints.gridx = 0; metricTemperatureConstraints.gridy = 0; metricTemperatureConstraints.weighty = 0.1; metricTemperatureConstraints.weightx = 1; metricTemperatureConstraints.fill = GridBagConstraints.BOTH; metricTemperatureConstraints.anchor = GridBagConstraints.FIRST_LINE_START; JPanel metricTemperaturePanel = new TemperaturePanel(frame, temperatures, TemperatureScales.CENTIGRADE); leftSideLayout.setConstraints(metricTemperaturePanel, metricTemperatureConstraints); leftSide.add(metricTemperaturePanel); GridBagConstraints metricDistancesPanelConstraints = new GridBagConstraints(); metricDistancesPanelConstraints.gridx = 0; metricDistancesPanelConstraints.gridy = 1; metricDistancesPanelConstraints.weighty = 0.3; metricDistancesPanelConstraints.weightx = 1; metricDistancesPanelConstraints.fill = GridBagConstraints.BOTH; metricDistancesPanelConstraints.anchor = GridBagConstraints.FIRST_LINE_START; JPanel metricDistancesPanel = new MetricDistancesPanel(frame, distances); leftSideLayout.setConstraints(metricDistancesPanel, metricDistancesPanelConstraints); leftSide.add(metricDistancesPanel); GridBagConstraints fahrenheitConstraints = new GridBagConstraints(); fahrenheitConstraints.gridx = 0; fahrenheitConstraints.gridy = 0; fahrenheitConstraints.weighty = 0.1; fahrenheitConstraints.weightx = 1; fahrenheitConstraints.fill = GridBagConstraints.BOTH; fahrenheitConstraints.anchor = GridBagConstraints.FIRST_LINE_START; JPanel fahrenheitTemperaturePanel = new TemperaturePanel(frame, temperatures, TemperatureScales.FAHRENHEIT); rightSideLayout.setConstraints(fahrenheitTemperaturePanel, fahrenheitConstraints); rightSide.add(fahrenheitTemperaturePanel); GridBagConstraints imperialDistancesPanelConstraints = new GridBagConstraints(); imperialDistancesPanelConstraints.gridx = 0; imperialDistancesPanelConstraints.gridy = 1; imperialDistancesPanelConstraints.weighty = 0.3; imperialDistancesPanelConstraints.weightx = 1; imperialDistancesPanelConstraints.fill = GridBagConstraints.BOTH; imperialDistancesPanelConstraints.anchor = GridBagConstraints.FIRST_LINE_START; JPanel imperialDistancesPanel = new ImperialDistancesPanel(frame, distances); rightSideLayout.setConstraints(imperialDistancesPanel, imperialDistancesPanelConstraints); rightSide.add(imperialDistancesPanel); GridBagConstraints metricWeightsConstraints = new GridBagConstraints(); metricWeightsConstraints.gridx = 0; metricWeightsConstraints.gridy = 2; metricWeightsConstraints.weighty = 0.6; metricWeightsConstraints.weightx = 1; metricWeightsConstraints.fill = GridBagConstraints.BOTH; metricWeightsConstraints.anchor = GridBagConstraints.FIRST_LINE_START; MetricWeightsPanel metricWeightsPanel = new MetricWeightsPanel(frame, weights); leftSideLayout.setConstraints(metricWeightsPanel, metricWeightsConstraints); leftSide.add(metricWeightsPanel); GridBagConstraints imperialWeightsConstraints = new GridBagConstraints(); imperialWeightsConstraints.gridx = 0; imperialWeightsConstraints.gridy = 2; imperialWeightsConstraints.weighty = 0.6; imperialWeightsConstraints.weightx = 1; imperialWeightsConstraints.fill = GridBagConstraints.BOTH; imperialWeightsConstraints.anchor = GridBagConstraints.FIRST_LINE_START; ImperialWeightsPanel imperialWeightsPanel = new ImperialWeightsPanel(frame, weights); rightSideLayout.setConstraints(imperialWeightsPanel, imperialWeightsConstraints); rightSide.add(imperialWeightsPanel); CSplit split = new CSplit(JSplitPane.HORIZONTAL_SPLIT, true, leftSide, rightSide); Container contentPane = frame.getContentPane(); contentPane.add(split); frame.validate(); frame.pack(); frame.setSize(600, 997); split.setResizeWeight(0.5); split.setDividerLocation(0.5); } // end of HappyHackingConverter constructor
public WizStepManyTextFields(Wizard w, String instr, Vector strings) { // store wizard? _instructions.setText(instr); _instructions.setWrapStyleWord(true); _instructions.setEditable(false); _instructions.setBorder(null); _instructions.setBackground(_mainPanel.getBackground()); _mainPanel.setBorder(new EtchedBorder()); GridBagLayout gb = new GridBagLayout(); _mainPanel.setLayout(gb); GridBagConstraints c = new GridBagConstraints(); c.ipadx = 3; c.ipady = 3; c.weightx = 0.0; c.weighty = 0.0; c.anchor = GridBagConstraints.EAST; JLabel image = new JLabel(""); // image.setMargin(new Insets(0, 0, 0, 0)); image.setIcon(WIZ_ICON); image.setBorder(null); c.gridx = 0; c.gridheight = GridBagConstraints.REMAINDER; c.gridy = 0; c.anchor = GridBagConstraints.NORTH; gb.setConstraints(image, c); _mainPanel.add(image); c.weightx = 0.0; c.gridx = 2; c.gridheight = 1; c.gridwidth = 3; c.gridy = 0; c.fill = GridBagConstraints.NONE; gb.setConstraints(_instructions, c); _mainPanel.add(_instructions); c.gridx = 1; c.gridy = 1; c.weightx = 0.0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; SpacerPanel spacer = new SpacerPanel(); gb.setConstraints(spacer, c); _mainPanel.add(spacer); c.gridx = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; int size = strings.size(); for (int i = 0; i < size; i++) { c.gridy = 2 + i; String s = (String) strings.elementAt(i); JTextField tf = new JTextField(s, 50); tf.setMinimumSize(new Dimension(200, 20)); tf.getDocument().addDocumentListener(this); _fields.addElement(tf); gb.setConstraints(tf, c); _mainPanel.add(tf); } c.gridx = 1; c.gridy = 3 + strings.size(); c.weightx = 0.0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; SpacerPanel spacer2 = new SpacerPanel(); gb.setConstraints(spacer2, c); _mainPanel.add(spacer2); }
public SaveDialog(Frame parent) { super(parent, true); this.setLayout(new BorderLayout()); // gather unsaved tab Set<Tab> unsaved = new LinkedHashSet<>(); for (Tab tab : MainPanel.getAllTab()) { if (!tab.isSaved()) { unsaved.add(tab); } } if (unsaved.isEmpty()) { // close directly this.setTitle("Confirm close"); // upper labels JPanel labels = new JPanel(new FlowLayout(FlowLayout.LEFT, 11, 7)); labels.add(iconLabel); labels.add(new MyLabel(" Do you really want to close RefluxEdit?")); // buttons JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7)); buttons.add( new MyButton("YES") { { SaveDialog.this.getRootPane().setDefaultButton(this); this.setFocusPainted(true); } @Override public void actionPerformed(ActionEvent ev) { close = true; SaveDialog.this.setVisible(false); } }); buttons.add( new MyButton("NO") { { this.setFocusPainted(true); } @Override public void actionPerformed(ActionEvent ev) { close = false; SaveDialog.this.setVisible(false); } }); buttons.setBorder(new EmptyBorder(0, 0, 5, 0)); // this.add(labels, BorderLayout.CENTER); this.add(buttons, BorderLayout.PAGE_END); } else { // ask save changes this.setTitle("Unsaved changes"); // upper components: icon and list JPanel upper = new JPanel(new GridBagLayout()); JPanel listPane = new JPanel(new BorderLayout()); final DefaultListModel<Tab> listModel = new DefaultListModel<>(); final JList<Tab> tabList = new JList<>(listModel); tabList.setFont(f13); tabList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); tabList.setCellRenderer( new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) (super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus)); if (value instanceof Tab) { String text = ((Tab) value).getTabLabel().getText(); label.setText(text.substring(1)); // remove "*" } return label; } }); for (Tab tab : unsaved) { listModel.addElement(tab); } tabList.getSelectionModel().setSelectionInterval(0, listModel.size() - 1); JScrollPane scrollPane = new JScrollPane(tabList); scrollPane.setPreferredSize(new Dimension(350, 170)); listPane.add(new MyLabel("The following tabs are unsaved:"), BorderLayout.PAGE_START); listPane.add(scrollPane, BorderLayout.CENTER); // setup upper GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 0; c.weighty = 1; c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.FIRST_LINE_START; upper.add(iconLabel, c); // c.gridx = 1; c.weightx = 1; c.fill = GridBagConstraints.BOTH; upper.add(listPane, c); // lower components: buttons JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7)); buttons.add( new MyButton("Save") { { this.setFocusPainted(true); this.setToolTipText("Save selected tab(s)"); SaveDialog.this.getRootPane().setDefaultButton(this); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { for (Tab tab : tabList.getSelectedValuesList()) { if (tab.getFile() != null) { try { tab.save(); MainPanel.close(tab); listModel.removeElement(tab); } catch (Exception ex) { exception(ex); break; } } else { File file = FileChooser.showPreferredFileDialog( RefluxEdit.getInstance(), FileChooser.SAVE, new String[0]); if (file != null) { try { tab.save(file, false); MainPanel.close(tab); listModel.removeElement(tab); } catch (Exception ex) { exception(ex); break; } } } } if (listModel.size() == 0) { RefluxEdit.getInstance().close(); } } }); buttons.add( new MyButton("Discard") { { this.setFocusPainted(true); this.setToolTipText("Discard selected tab(s)"); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { for (Tab tab : tabList.getSelectedValuesList()) { MainPanel.close(tab); listModel.removeElement(tab); } if (listModel.size() == 0) { RefluxEdit.getInstance().close(); } } }); buttons.add( new MyButton("Close") { { this.setFocusPainted(true); this.setToolTipText("Close RefluxEdit"); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { SaveDialog.this.close = true; SaveDialog.this.setVisible(false); } }); buttons.add( new MyButton("Cancel") { { this.setFocusPainted(true); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { SaveDialog.this.close = false; SaveDialog.this.setVisible(false); } }); this.add(upper, BorderLayout.CENTER); this.add(buttons, BorderLayout.PAGE_END); } }
private void initialize() { setName("NewsPanel"); setLayout(new GridBagLayout()); refreshLanguage(); // We create the components new TextComponentClipboardMenu(uploadPrioTextField, language); new TextComponentClipboardMenu(downloadPrioTextField, language); new TextComponentClipboardMenu(displayDaysTextField, language); new TextComponentClipboardMenu(downloadDaysTextField, language); new TextComponentClipboardMenu(messageBaseTextField, language); new TextComponentClipboardMenu(minimumIntervalTextField, language); new TextComponentClipboardMenu(concurrentUpdatesTextField, language); new TextComponentClipboardMenu(altEditTextField, language); // Adds all of the components final GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.WEST; constraints.weighty = 0.0; constraints.weightx = 0; constraints.insets = new Insets(0, 5, 5, 5); constraints.gridy = 0; constraints.gridx = 0; add(displayDaysLabel, constraints); constraints.gridx = 1; add(displayDaysTextField, constraints); constraints.gridx = 0; constraints.gridy++; add(downloadDaysLabel, constraints); constraints.gridx = 1; add(downloadDaysTextField, constraints); constraints.gridx = 0; constraints.gridy++; constraints.gridwidth = 2; add(alwaysDownloadBackloadCheckBox, constraints); constraints.gridwidth = 1; constraints.gridx = 0; constraints.gridy++; add(messageBaseLabel, constraints); constraints.gridx = 1; add(messageBaseTextField, constraints); constraints.gridy++; constraints.gridx = 0; add(uploadPrioLabel, constraints); constraints.gridx = 1; add(uploadPrioTextField, constraints); constraints.gridy++; constraints.gridx = 0; add(downloadPrioLabel, constraints); constraints.gridx = 1; add(downloadPrioTextField, constraints); constraints.gridx = 0; constraints.gridwidth = 2; constraints.gridy++; add(automaticBoardUpdateCheckBox, constraints); constraints.gridy++; add(getUpdatePanel(), constraints); constraints.gridy++; add(useOneConnectionForMessagesCheckBox, constraints); constraints.gridy++; add(storeSentMessagesCheckBox, constraints); constraints.gridy++; add(silentlyRetryCheckBox, constraints); constraints.gridwidth = 1; constraints.insets = new Insets(0, 5, 0, 5); constraints.gridy++; constraints.gridx = 0; add(altEditCheckBox, constraints); constraints.gridx = 1; constraints.weightx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; add(altEditTextField, constraints); constraints.weightx = 0; constraints.fill = GridBagConstraints.NONE; // glue constraints.gridy++; constraints.gridx = 0; constraints.gridwidth = 2; constraints.fill = GridBagConstraints.BOTH; constraints.weightx = 1; constraints.weighty = 1; add(new JLabel(""), constraints); // Add listeners automaticBoardUpdateCheckBox.addActionListener(listener); altEditCheckBox.addChangeListener(listener); }
// Public constructor public ElectronicOrganFrame(String title) { // Call parent constructor to give title to frame super(title); // Make this frame its own window listener addWindowListener(windowListener); // Panel components: waveformPanel waveformPanel.setBorder( new TitledBorder(new BevelBorder(BevelBorder.RAISED), "Waveform Options")); GridBagLayout waveformPanelGridBag = new GridBagLayout(); GridBagConstraints waveformPanelConstr = new GridBagConstraints(); waveformPanel.setLayout(waveformPanelGridBag); waveformPanelConstr.anchor = GridBagConstraints.CENTER; waveformPanelConstr.weightx = 1.0; waveformPanelConstr.weighty = 1.0; waveformPanelConstr.fill = GridBagConstraints.BOTH; waveformPanelConstr.gridx = 0; waveformPanelConstr.gridy = 0; waveformPanelConstr.gridwidth = 1; waveformPanelConstr.gridheight = 1; waveformPanelGridBag.setConstraints(sineButton, waveformPanelConstr); waveformPanel.add(sineButton); waveformPanelRadio.add(sineButton); sineButton.addActionListener(actionListener); waveformPanelConstr.gridx = 1; waveformPanelConstr.gridy = 0; waveformPanelConstr.gridwidth = 1; waveformPanelConstr.gridheight = 1; waveformPanelGridBag.setConstraints(squareButton, waveformPanelConstr); waveformPanel.add(squareButton); waveformPanelRadio.add(squareButton); squareButton.addActionListener(actionListener); waveformPanelConstr.gridx = 2; waveformPanelConstr.gridy = 0; waveformPanelConstr.gridwidth = 1; waveformPanelConstr.gridheight = 1; waveformPanelGridBag.setConstraints(sawtoothButton, waveformPanelConstr); waveformPanel.add(sawtoothButton); waveformPanelRadio.add(sawtoothButton); sawtoothButton.addActionListener(actionListener); waveformPanelConstr.gridx = 3; waveformPanelConstr.gridy = 0; waveformPanelConstr.gridwidth = 1; waveformPanelConstr.gridheight = 1; waveformPanelGridBag.setConstraints(triangleButton, waveformPanelConstr); waveformPanel.add(triangleButton); waveformPanelRadio.add(triangleButton); triangleButton.addActionListener(actionListener); // Panel components: exitPanel exitPanel.setLayout(new GridLayout(1, 5)); exitPanel.add(label1); exitPanel.add(label2); exitPanel.add(exitButton); exitButton.addActionListener(actionListener); exitPanel.add(label3); exitPanel.add(label4); GridBagLayout thisGridBag = new GridBagLayout(); GridBagConstraints thisConstr = new GridBagConstraints(); this.getContentPane().setLayout(thisGridBag); thisConstr.anchor = GridBagConstraints.CENTER; thisConstr.weightx = 1.0; thisConstr.weighty = 1.0; thisConstr.fill = GridBagConstraints.BOTH; thisConstr.gridx = 0; thisConstr.gridy = 0; thisConstr.gridwidth = 3; thisConstr.gridheight = 1; thisGridBag.setConstraints(label5, thisConstr); this.getContentPane().add(label5); thisConstr.gridx = 0; thisConstr.gridy = 1; thisConstr.gridwidth = 1; thisConstr.gridheight = 1; thisGridBag.setConstraints(label6, thisConstr); this.getContentPane().add(label6); thisConstr.gridx = 1; thisConstr.gridy = 1; thisConstr.gridwidth = 1; thisConstr.gridheight = 1; thisGridBag.setConstraints(waveformPanel, thisConstr); this.getContentPane().add(waveformPanel); thisConstr.gridx = 2; thisConstr.gridy = 1; thisConstr.gridwidth = 1; thisConstr.gridheight = 1; thisGridBag.setConstraints(label7, thisConstr); this.getContentPane().add(label7); thisConstr.gridx = 1; thisConstr.gridy = 2; thisConstr.gridwidth = 1; thisConstr.gridheight = 1; thisGridBag.setConstraints(exitPanel, thisConstr); this.getContentPane().add(exitPanel); // Set frame size and show it setSize(500, 200); setVisible(true); } // Frame constructor ElectronicOrganFrame ()
public ClassMemberSpecificationDialog(JDialog owner, boolean isField) { super(owner, true); setResizable(true); // Create some constraints that can be reused. GridBagConstraints constraints = new GridBagConstraints(); constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(1, 2, 1, 2); GridBagConstraints constraintsStretch = new GridBagConstraints(); constraintsStretch.fill = GridBagConstraints.HORIZONTAL; constraintsStretch.weightx = 1.0; constraintsStretch.anchor = GridBagConstraints.WEST; constraintsStretch.insets = constraints.insets; GridBagConstraints constraintsLast = new GridBagConstraints(); constraintsLast.gridwidth = GridBagConstraints.REMAINDER; constraintsLast.anchor = GridBagConstraints.WEST; constraintsLast.insets = constraints.insets; GridBagConstraints constraintsLastStretch = new GridBagConstraints(); constraintsLastStretch.gridwidth = GridBagConstraints.REMAINDER; constraintsLastStretch.fill = GridBagConstraints.HORIZONTAL; constraintsLastStretch.weightx = 1.0; constraintsLastStretch.anchor = GridBagConstraints.WEST; constraintsLastStretch.insets = constraints.insets; GridBagConstraints panelConstraints = new GridBagConstraints(); panelConstraints.gridwidth = GridBagConstraints.REMAINDER; panelConstraints.fill = GridBagConstraints.HORIZONTAL; panelConstraints.weightx = 1.0; panelConstraints.weighty = 0.0; panelConstraints.anchor = GridBagConstraints.NORTHWEST; panelConstraints.insets = constraints.insets; GridBagConstraints stretchPanelConstraints = new GridBagConstraints(); stretchPanelConstraints.gridwidth = GridBagConstraints.REMAINDER; stretchPanelConstraints.fill = GridBagConstraints.BOTH; stretchPanelConstraints.weightx = 1.0; stretchPanelConstraints.weighty = 1.0; stretchPanelConstraints.anchor = GridBagConstraints.NORTHWEST; stretchPanelConstraints.insets = constraints.insets; GridBagConstraints labelConstraints = new GridBagConstraints(); labelConstraints.anchor = GridBagConstraints.CENTER; labelConstraints.insets = new Insets(2, 10, 2, 10); GridBagConstraints lastLabelConstraints = new GridBagConstraints(); lastLabelConstraints.gridwidth = GridBagConstraints.REMAINDER; lastLabelConstraints.anchor = GridBagConstraints.CENTER; lastLabelConstraints.insets = labelConstraints.insets; GridBagConstraints okButtonConstraints = new GridBagConstraints(); okButtonConstraints.weightx = 1.0; okButtonConstraints.weighty = 1.0; okButtonConstraints.anchor = GridBagConstraints.SOUTHEAST; okButtonConstraints.insets = new Insets(4, 4, 8, 4); GridBagConstraints cancelButtonConstraints = new GridBagConstraints(); cancelButtonConstraints.gridwidth = GridBagConstraints.REMAINDER; cancelButtonConstraints.weighty = 1.0; cancelButtonConstraints.anchor = GridBagConstraints.SOUTHEAST; cancelButtonConstraints.insets = okButtonConstraints.insets; GridBagLayout layout = new GridBagLayout(); Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.RAISED); this.isField = isField; // Create the access panel. JPanel accessPanel = new JPanel(layout); accessPanel.setBorder( BorderFactory.createTitledBorder(etchedBorder, GUIResources.getMessage("access"))); accessPanel.add(Box.createGlue(), labelConstraints); accessPanel.add(new JLabel(GUIResources.getMessage("required")), labelConstraints); accessPanel.add(new JLabel(GUIResources.getMessage("not")), labelConstraints); accessPanel.add(new JLabel(GUIResources.getMessage("dontCare")), labelConstraints); accessPanel.add(Box.createGlue(), constraintsLastStretch); publicRadioButtons = addRadioButtonTriplet("Public", accessPanel); privateRadioButtons = addRadioButtonTriplet("Private", accessPanel); protectedRadioButtons = addRadioButtonTriplet("Protected", accessPanel); staticRadioButtons = addRadioButtonTriplet("Static", accessPanel); finalRadioButtons = addRadioButtonTriplet("Final", accessPanel); if (isField) { volatileRadioButtons = addRadioButtonTriplet("Volatile", accessPanel); transientRadioButtons = addRadioButtonTriplet("Transient", accessPanel); } else { synchronizedRadioButtons = addRadioButtonTriplet("Synchronized", accessPanel); nativeRadioButtons = addRadioButtonTriplet("Native", accessPanel); abstractRadioButtons = addRadioButtonTriplet("Abstract", accessPanel); strictRadioButtons = addRadioButtonTriplet("Strict", accessPanel); } // Create the type panel. JPanel typePanel = new JPanel(layout); typePanel.setBorder( BorderFactory.createTitledBorder( etchedBorder, GUIResources.getMessage(isField ? "type" : "returnType"))); typePanel.add(typeTextField, constraintsLastStretch); // Create the name panel. JPanel namePanel = new JPanel(layout); namePanel.setBorder( BorderFactory.createTitledBorder(etchedBorder, GUIResources.getMessage("name"))); namePanel.add(nameTextField, constraintsLastStretch); // Create the arguments panel. JPanel argumentsPanel = new JPanel(layout); argumentsPanel.setBorder( BorderFactory.createTitledBorder(etchedBorder, GUIResources.getMessage("arguments"))); argumentsPanel.add(argumentsTextField, constraintsLastStretch); // Create the Ok button. JButton okButton = new JButton(GUIResources.getMessage("ok")); okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { returnValue = APPROVE_OPTION; hide(); } }); // Create the Cancel button. JButton cancelButton = new JButton(GUIResources.getMessage("cancel")); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { hide(); } }); // Add all panels to the main panel. JPanel mainPanel = new JPanel(layout); mainPanel.add(accessPanel, panelConstraints); mainPanel.add(typePanel, panelConstraints); mainPanel.add(namePanel, panelConstraints); if (!isField) { mainPanel.add(argumentsPanel, panelConstraints); } mainPanel.add(okButton, okButtonConstraints); mainPanel.add(cancelButton, cancelButtonConstraints); getContentPane().add(mainPanel); }