public FoodEditor(JFrame parent, RItem data) { super(parent, "Scroll Editor: " + data.id); this.data = data; JPanel itemProps = new JPanel(); GroupLayout layout = new GroupLayout(itemProps); itemProps.setLayout(layout); layout.setAutoCreateGaps(true); JLabel nameLabel = new JLabel("Name: "); JLabel costLabel = new JLabel("Cost: "); JLabel colorLabel = new JLabel("Color: "); JLabel charLabel = new JLabel("Character: "); JLabel weightLabel = new JLabel("Weight: "); JLabel spellLabel = new JLabel("Spell: "); nameField = new JTextField(15); costField = new JFormattedTextField(NeonFormat.getIntegerInstance()); colorBox = new JComboBox<String>(ColorFactory.getColorNames()); colorBox.setBackground(Color.black); colorBox.setRenderer(new ColorCellRenderer()); colorBox.addActionListener(new ColorListener(colorBox)); charField = new JFormattedTextField(getMaskFormatter("*", 'X')); weightField = new JFormattedTextField(NeonFormat.getFloatInstance()); spellBox = new JComboBox<String>(loadSpells()); JLabel nameHelpLabel = HelpLabels.getNameHelpLabel(); JLabel costHelpLabel = HelpLabels.getCostHelpLabel(); JLabel colorHelpLabel = HelpLabels.getColorHelpLabel(); JLabel charHelpLabel = HelpLabels.getCharHelpLabel(); JLabel weightHelpLabel = HelpLabels.getWeightHelpLabel(); JLabel foodHelpLabel = HelpLabels.getFoodEffectHelpLabel(); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(nameLabel) .addComponent(nameField) .addComponent(nameHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(costLabel) .addComponent(costField) .addComponent(costHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(colorLabel) .addComponent(colorBox) .addComponent(colorHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(charLabel) .addComponent(charField) .addComponent(charHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(weightLabel) .addComponent(weightField) .addComponent(weightHelpLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(spellLabel) .addComponent(spellBox) .addComponent(foodHelpLabel))); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(nameLabel) .addComponent(costLabel) .addComponent(colorLabel) .addComponent(charLabel) .addComponent(weightLabel) .addComponent(spellLabel)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING, false) .addComponent( nameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(costField) .addComponent(colorBox) .addComponent(charField) .addComponent(weightField) .addComponent(spellBox)) .addGap(10) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING, false) .addComponent(nameHelpLabel) .addComponent(costHelpLabel) .addComponent(colorHelpLabel) .addComponent(charHelpLabel) .addComponent(weightHelpLabel) .addComponent(foodHelpLabel))); JScrollPane propScroller = new JScrollPane(itemProps); propScroller.setBorder(new TitledBorder("Properties")); frame.add(propScroller, BorderLayout.CENTER); }
/** * Private method used to initialize everything in the dialog box This method was generated by * Forte, which was used to create the initial layout of the dialog box */ @SuppressWarnings({"rawtypes", "unchecked"}) private void initComponents() { buttonGroup1 = new ButtonGroup(); jPanel1 = new JPanel(); jPanel1.setPreferredSize(new Dimension(350, 270)); jButtonAdd = new JButton(); jButtonCancel = new JButton(); jLabel1 = new JLabel(); jLabel2 = new JLabel(); jLabel4 = new JLabel(); jLabel8 = new JLabel(); jButtonClear = new JButton(); jTextFieldName = new JTextField(); jTextFieldName.setToolTipText("Enter full name here"); jTextFieldPhone = new JTextField(); jTextFieldPhone.setToolTipText("xxx-xxx-xxxx"); jTextFieldNotes = new JTextField(); jComboBoxStartHours = new JComboBox(); jSeparator1 = new JSeparator(); jRadioButtonAM = new JRadioButton(); jRadioButtonPM = new JRadioButton(); jComboBoxStartMinutes = new JComboBox(); jLabel11 = new JLabel(); addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } }); jButtonAdd.setText("Add"); jButtonAdd.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButtonAddMouseClicked(evt); } }); jButtonCancel.setText("Cancel"); jButtonCancel.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButtonCancelMouseClicked(evt); } }); jLabel1.setText("Name"); jLabel2.setText("Phone Number"); jLabel4.setText("Appointment Time"); jLabel8.setText("Notes"); jButtonClear.setText("Clear"); jButtonClear.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButtonClearMouseClicked(evt); } }); jComboBoxStartHours.setModel( new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "9", "10", "11", "12"})); jRadioButtonAM.setText("AM"); buttonGroup1.add(jRadioButtonAM); jRadioButtonPM.setText("PM"); buttonGroup1.add(jRadioButtonPM); jRadioButtonPM.setSelected(true); jComboBoxStartMinutes.setModel(new DefaultComboBoxModel(new String[] {"00"})); jLabel11.setText("Duration: 1 hour"); getContentPane().add(jPanel1, BorderLayout.CENTER); JLabel lblXxxxxxxxxx = new JLabel("xxx-xxx-xxxx"); GroupLayout gl_jPanel1 = new GroupLayout(jPanel1); gl_jPanel1.setHorizontalGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING) .addGroup( gl_jPanel1 .createSequentialGroup() .addGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING) .addGroup( gl_jPanel1 .createSequentialGroup() .addGap(10) .addGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING, false) .addGroup( gl_jPanel1 .createSequentialGroup() .addComponent( jLabel1, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE) .addGap(40) .addComponent( jTextFieldName, GroupLayout.PREFERRED_SIZE, 198, GroupLayout.PREFERRED_SIZE)) .addGroup( gl_jPanel1 .createSequentialGroup() .addComponent(jLabel2) .addGap(50) .addGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING) .addComponent(lblXxxxxxxxxx) .addComponent(jTextFieldPhone))))) .addGroup( gl_jPanel1 .createSequentialGroup() .addContainerGap() .addGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING, false) .addGroup( gl_jPanel1 .createSequentialGroup() .addComponent( jButtonAdd, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE) .addGap(18) .addComponent( jButtonClear, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE) .addGap(18) .addComponent( jButtonCancel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent( jSeparator1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGroup( gl_jPanel1 .createSequentialGroup() .addComponent( jLabel8, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE) .addGap(30) .addComponent( jTextFieldNotes, GroupLayout.PREFERRED_SIZE, 196, GroupLayout.PREFERRED_SIZE)))) .addGroup( gl_jPanel1 .createSequentialGroup() .addContainerGap() .addGroup( gl_jPanel1 .createParallelGroup(Alignment.TRAILING, false) .addComponent( jLabel11, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel4, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)) .addGap(18) .addComponent( jComboBoxStartHours, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE) .addComponent( jComboBoxStartMinutes, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE) .addGap(10) .addComponent( jRadioButtonAM, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE) .addComponent( jRadioButtonPM, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))) .addContainerGap(22, Short.MAX_VALUE))); gl_jPanel1.setVerticalGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING) .addGroup( gl_jPanel1 .createSequentialGroup() .addGap(20) .addGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING) .addComponent(jLabel1) .addComponent( jTextFieldName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING) .addComponent(jLabel2) .addComponent( jTextFieldPhone, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(lblXxxxxxxxxx) .addGap(11) .addGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING) .addComponent(jLabel4) .addComponent( jComboBoxStartHours, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent( jComboBoxStartMinutes, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent( jRadioButtonAM, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE) .addComponent( jRadioButtonPM, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(jLabel11) .addGap(16) .addComponent( jSeparator1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addGroup( gl_jPanel1 .createParallelGroup(Alignment.LEADING) .addComponent(jLabel8) .addComponent( jTextFieldNotes, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(18) .addGroup( gl_jPanel1 .createParallelGroup(Alignment.BASELINE) .addComponent(jButtonAdd) .addComponent(jButtonCancel) .addComponent(jButtonClear)) .addGap(265))); gl_jPanel1.setAutoCreateGaps(true); jPanel1.setLayout(gl_jPanel1); pack(); }
protected JComponent createSouthPanel() { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0)); JPanel buttonPanel = new JPanel(); if (SystemInfo.isMac) { panel.add(buttonPanel, BorderLayout.EAST); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); if (!UIUtil.isUnderDarcula()) { myHelpButton.putClientProperty("JButton.buttonType", "help"); } if (UIUtil.isUnderAquaLookAndFeel()) { myHelpButton.setText(""); } JPanel leftPanel = new JPanel(); if (ApplicationInfo.contextHelpAvailable()) { leftPanel.add(myHelpButton); } leftPanel.add(myCancelButton); panel.add(leftPanel, BorderLayout.WEST); if (mySteps.size() > 1) { buttonPanel.add(Box.createHorizontalStrut(5)); buttonPanel.add(myPreviousButton); } buttonPanel.add(Box.createHorizontalStrut(5)); buttonPanel.add(myNextButton); } else { panel.add(buttonPanel, BorderLayout.CENTER); GroupLayout layout = new GroupLayout(buttonPanel); buttonPanel.setLayout(layout); layout.setAutoCreateGaps(true); final GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup(); final GroupLayout.ParallelGroup vGroup = layout.createParallelGroup(); final Collection<Component> buttons = ContainerUtil.newArrayListWithExpectedSize(5); final boolean helpAvailable = ApplicationInfo.contextHelpAvailable(); if (helpAvailable && UIUtil.isUnderGTKLookAndFeel()) { add(hGroup, vGroup, buttons, myHelpButton); } add(hGroup, vGroup, null, Box.createHorizontalGlue()); if (mySteps.size() > 1) { add(hGroup, vGroup, buttons, myPreviousButton); } add(hGroup, vGroup, buttons, myNextButton, myCancelButton); if (helpAvailable && !UIUtil.isUnderGTKLookAndFeel()) { add(hGroup, vGroup, buttons, myHelpButton); } layout.setHorizontalGroup(hGroup); layout.setVerticalGroup(vGroup); layout.linkSize(buttons.toArray(new Component[buttons.size()])); } myPreviousButton.setEnabled(false); myPreviousButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { doPreviousAction(); } }); myNextButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { if (isLastStep()) { // Commit data of current step and perform OK action final Step currentStep = mySteps.get(myCurrentStep); LOG.assertTrue(currentStep != null); try { currentStep._commit(true); doOKAction(); } catch (final CommitStepException exc) { String message = exc.getMessage(); if (message != null) { Messages.showErrorDialog(myContentPanel, message); } } } else { doNextAction(); } } }); myCancelButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { doCancelAction(); } }); myHelpButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { helpAction(); } }); return panel; }
private void makeAndSetTabComponents() { final String[] tabTitles = {"Libraries", "Modes", "Tools", "Examples", "Updates"}; tabLabels = new JLabel[4]; for (int i = 0; i < 4; i++) { final int temp = i; tabLabels[i] = new JLabel(tabTitles[i]) { @Override protected void paintComponent(Graphics g) { g.setClip( Toolkit.createRoundRect( 0, 0, getWidth(), getHeight(), temp == 0 ? 6 : 0, temp == 3 ? 6 : 0, 0, 0)); super.paintComponent(g); } }; tabLabels[i].setForeground(Color.WHITE); tabLabels[i].setBackground(new Color(0x2d4251)); tabLabels[i].setOpaque(true); tabLabels[i].setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); tabLabels[i].setPreferredSize(new Dimension(TAB_WIDTH, TAB_HEIGHT)); tabLabels[i].setHorizontalAlignment(SwingConstants.CENTER); tabLabels[i].setFont(Toolkit.getSansFont(14, Font.BOLD)); tabbedPane.setTabComponentAt(i, tabLabels[i]); } updateTabPanel = new JPanel() { @Override protected void paintComponent(Graphics g) { g.setClip(Toolkit.createRoundRect(0, 0, getWidth(), getHeight(), 6, 6, 0, 0)); super.paintComponent(g); } }; ; updateTabLabel = new JLabel("Updates"); updateTabLabel.setFont(Toolkit.getSansFont(14, Font.BOLD)); numberLabel.setVerticalTextPosition(SwingConstants.CENTER); numberLabel.setHorizontalTextPosition(SwingConstants.CENTER); numberLabel.setFont(Toolkit.getSansFont(14, Font.BOLD)); numberLabel.setForeground(Color.WHITE); updateTabPanel.setOpaque(true); updateTabPanel.setBackground(new Color(0x2d4251)); updateTabLabel.setForeground(Color.WHITE); updateTabPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); updateTabPanel.setPreferredSize(new Dimension(TAB_WIDTH, TAB_HEIGHT)); tabbedPane.setTabComponentAt(4, updateTabPanel); GroupLayout tabLayout = new GroupLayout(updateTabPanel); tabLayout.setAutoCreateGaps(true); updateTabPanel.setLayout(tabLayout); tabLayout.setHorizontalGroup( tabLayout .createSequentialGroup() .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(updateTabLabel) .addComponent(numberLabel) .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); tabLayout.setVerticalGroup( tabLayout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(numberLabel) .addComponent(updateTabLabel)); numberLabel.setVisible(false); }
public FindReplaceDialog(RobocodeEditor owner) { super(owner, false); editor = owner; GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); JPanel optionsPanel = new JPanel(); optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS)); optionsPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Options")); optionsPanel.add(getCaseSensitiveCheckBox()); optionsPanel.add(getWholeWordCheckBox()); optionsPanel.setAlignmentY(TOP_ALIGNMENT); JPanel usePanel = new JPanel(); usePanel.setLayout(new BoxLayout(usePanel, BoxLayout.Y_AXIS)); usePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Use")); usePanel.add(getLiteralButton()); usePanel.add(getWildCardsButton()); usePanel.add(getRegexButton()); usePanel.setAlignmentY(TOP_ALIGNMENT); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(getLiteralButton()); buttonGroup.add(getWildCardsButton()); buttonGroup.add(getRegexButton()); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(LEADING) .addGroup( layout .createSequentialGroup() .addComponent(getFindLabel()) .addComponent(getFindTextField())) .addGroup( layout .createSequentialGroup() .addComponent(getReplaceLabel()) .addComponent(getReplaceTextField())) .addGroup( layout .createSequentialGroup() .addComponent(optionsPanel) .addComponent(usePanel))) .addGroup( layout .createParallelGroup(LEADING) .addComponent(getFindNextButton()) .addComponent(getReplaceFindButton()) .addComponent(getReplaceButton()) .addComponent(getReplaceAllButton()) .addComponent(getCloseButton()))); layout.linkSize(SwingConstants.HORIZONTAL, getFindLabel(), getReplaceLabel()); layout.linkSize( SwingConstants.HORIZONTAL, getFindNextButton(), getReplaceFindButton(), getReplaceButton(), getReplaceAllButton(), getCloseButton()); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(BASELINE) .addComponent(getFindLabel()) .addComponent(getFindTextField()) .addComponent(getFindNextButton())) .addGroup( layout .createParallelGroup(BASELINE) .addComponent(getReplaceLabel()) .addComponent(getReplaceTextField()) .addComponent(getReplaceButton())) .addGroup( layout .createParallelGroup(BASELINE) .addComponent(optionsPanel) .addComponent(usePanel) .addGroup( layout .createSequentialGroup() .addComponent(getReplaceFindButton()) .addComponent(getReplaceAllButton()) .addComponent(getCloseButton())))); pack(); setResizable(false); }
private void initGUI() { /** 北部panel */ Font font_12 = new Font("微软雅黑", Font.PLAIN, 14); /** 设置字体 */ crackButton.setFont(font_12); northPane = new JPanel(new FlowLayout(FlowLayout.LEFT)); northPane.setBorder(BorderFactory.createTitledBorder("破解地址")); GroupLayout layout_north = new GroupLayout(northPane); northPane.setLayout(layout_north); /** 自动设定组件、组之间的间隙 */ layout_north.setAutoCreateGaps(true); layout_north.setAutoCreateContainerGaps(true); /** 垂直一 */ GroupLayout.ParallelGroup hpg_north_1 = layout_north.createParallelGroup(GroupLayout.Alignment.LEADING); hpg_north_1.addComponent(label_for_pageUrl); /** 垂直二 */ GroupLayout.ParallelGroup hpg_north_2 = layout_north.createParallelGroup(GroupLayout.Alignment.LEADING); hpg_north_2.addComponent(pageUrl); /** 垂直三 */ GroupLayout.ParallelGroup hpg_north_3 = layout_north.createParallelGroup(GroupLayout.Alignment.LEADING); hpg_north_3.addComponent(crackButton); /** 垂直 */ layout_north.setHorizontalGroup( layout_north .createSequentialGroup() .addGroup(hpg_north_1) .addGroup(hpg_north_2) .addGroup(hpg_north_3)); /** 水平一 */ GroupLayout.ParallelGroup vpg_north_1 = layout_north.createParallelGroup(GroupLayout.Alignment.CENTER); vpg_north_1.addComponent(label_for_pageUrl).addComponent(pageUrl).addComponent(crackButton); /** 水平 */ layout_north.setVerticalGroup(layout_north.createSequentialGroup().addGroup(vpg_north_1)); this.add(northPane, BorderLayout.NORTH); /** 南部panel */ mCode.setColumns(50); regCode.setColumns(50); mCode.setEditable(false); southPane = new JPanel(new FlowLayout(FlowLayout.LEFT)); southPane.setBorder(BorderFactory.createTitledBorder("软件注册")); southPane.add(label_for_mCode); southPane.add(mCode); southPane.add(label_for_regCode); southPane.add(regCode); /** 新增为布局的南部 */ this.add(southPane, BorderLayout.SOUTH); /** 中部panel */ videoInfo = new JPanel(); videoInfo.setBorder(BorderFactory.createTitledBorder("视频信息")); GroupLayout layout = new GroupLayout(videoInfo); videoInfo.setLayout(layout); /** 自动设定组件、组之间的间隙 */ layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); JButton cancelButton = new JButton("Cancel"); /** LEADING -- 左对齐 BASELINE -- 底部对齐 CENTER -- 中心对齐 */ /** 垂直一 */ GroupLayout.ParallelGroup hpg1 = layout.createParallelGroup(GroupLayout.Alignment.LEADING); hpg1.addComponent(label_for_title) .addComponent(label_for_time) .addComponent(label_for_addTime) .addComponent(label_for_imgPre) .addComponent(label_for_crack_video) .addComponent(label_for_fileSize); /** 垂直二 */ GroupLayout.ParallelGroup hpg2 = layout.createParallelGroup(GroupLayout.Alignment.LEADING); hpg2.addComponent(title) .addComponent(time) .addComponent(addTime) .addComponent(image) .addComponent(crackVideo) .addComponent(fileSize); /** 垂直三 */ GroupLayout.ParallelGroup hpg3 = layout.createParallelGroup(GroupLayout.Alignment.LEADING); hpg3.addComponent(cancelButton); /** 垂直 */ layout.setHorizontalGroup( layout.createSequentialGroup().addGroup(hpg1).addGroup(hpg2).addGroup(hpg3)); /** 设定两个Button在水平方向一样宽 */ // layout.linkSize(SwingConstants.HORIZONTAL, new Component[]{crackButton, // cancelButton}); /** 水平一 */ GroupLayout.ParallelGroup vpg1 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE); // vpg1.addComponent(crackButton); /** 水平二 */ GroupLayout.ParallelGroup vpg2 = layout.createParallelGroup(GroupLayout.Alignment.CENTER); vpg2.addComponent(label_for_title).addComponent(title).addComponent(cancelButton); /** 水平三 */ GroupLayout.ParallelGroup vpg3 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE); vpg3.addComponent(label_for_time).addComponent(time); /** 水平四 */ GroupLayout.ParallelGroup vpg4 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE); vpg4.addComponent(label_for_addTime).addComponent(addTime); /** 水平五 */ GroupLayout.ParallelGroup vpg5 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE); vpg5.addComponent(label_for_imgPre).addComponent(image); /** 水平六 */ GroupLayout.ParallelGroup vpg6 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE); vpg6.addComponent(label_for_crack_video).addComponent(crackVideo); /** 水平七 */ GroupLayout.ParallelGroup vpg7 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE); vpg7.addComponent(label_for_fileSize).addComponent(fileSize); /** 水平 */ layout.setVerticalGroup( layout .createSequentialGroup() .addGroup(vpg1) .addGroup(vpg2) .addGroup(vpg3) .addGroup(vpg4) .addGroup(vpg5) .addGroup(vpg6) .addGroup(vpg7)); this.add(videoInfo, BorderLayout.CENTER); }
public void createGUI() { JButton submitButton = new JButton("Submit"); submitButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // get text from input fields inputPath = inputField.getText(); outputPath = outputField.getText(); buttonPressed = true; } }); JPanel inputPanel = new JPanel(); inputPanel.add(new JLabel("Input Path")); inputPanel.add(inputField); JLabel inputLabel = new JLabel("Input Path"); JLabel outputLabel = new JLabel("Output Path"); JPanel content = new JPanel(); content.setLayout(new BorderLayout()); JPanel textFieldsContent = new JPanel(); GroupLayout layout = new GroupLayout(textFieldsContent); textFieldsContent.setLayout(layout); // setting to true creates gaps between components layout.setAutoCreateGaps(true); // setting to true creates gaps between components and edge of container layout.setAutoCreateContainerGaps(true); // horizontal axis GroupLayout.SequentialGroup horizontalGroup = layout.createSequentialGroup(); // each sequential group contains two parallel groups. // one will contain labels, other will contain text fields horizontalGroup.addGroup( layout.createParallelGroup().addComponent(inputLabel).addComponent(outputLabel)); horizontalGroup.addGroup( layout.createParallelGroup().addComponent(inputField).addComponent(outputField)); layout.setHorizontalGroup(horizontalGroup); // vertical axis GroupLayout.SequentialGroup verticalGroup = layout.createSequentialGroup(); verticalGroup.addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(inputLabel) .addComponent(inputField)); verticalGroup.addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(outputLabel) .addComponent(outputField)); layout.setVerticalGroup(verticalGroup); content.add(textFieldsContent, BorderLayout.CENTER); content.add(submitButton, BorderLayout.PAGE_END); window.setContentPane(content); window.setSize(350, 200); window.setLocation(100, 100); window.setVisible(true); }
public fileBackupProgram(JFrame frame) { super(new BorderLayout()); this.frame = frame; errorDialog = new CustomDialog(frame, "Please enter a new name for the error log", this); errorDialog.pack(); moveDialog = new CustomDialog(frame, "Please enter a new name for the move log", this); moveDialog.pack(); printer = new FilePrinter(); timers = new ArrayList<>(); log = new JTextArea(5, 20); log.setMargin(new Insets(5, 5, 5, 5)); log.setEditable(false); JScrollPane logScrollPane = new JScrollPane(log); Object obj; copy = true; listModel = new DefaultListModel(); // destListModel = new DefaultListModel(); directoryList = new directoryStorage(); // Create a file chooser fc = new JFileChooser(); // Create the menu bar. menuBar = new JMenuBar(); // Build the first menu. menu = new JMenu("File"); menu.getAccessibleContext() .setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); editError = new JMenuItem("Save Error Log As..."); editError .getAccessibleContext() .setAccessibleDescription("Change the name of the error log file"); editError.addActionListener(new ErrorListener()); menu.add(editError); editMove = new JMenuItem("Save Move Log As..."); editMove .getAccessibleContext() .setAccessibleDescription("Change the name of the move log file"); editMove.addActionListener(new MoveListener()); menu.add(editMove); exit = new JMenuItem("Exit"); exit.getAccessibleContext().setAccessibleDescription("Exit the Program"); exit.addActionListener(new CloseListener()); menu.add(exit); frame.setJMenuBar(menuBar); // Uncomment one of the following lines to try a different // file selection mode. The first allows just directories // to be selected (and, at least in the Java look and feel, // shown). The second allows both files and directories // to be selected. If you leave these lines commented out, // then the default mode (FILES_ONLY) will be used. // fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); openButton = new JButton(openString); openButton.setActionCommand(openString); openButton.addActionListener(new OpenListener()); destButton = new JButton(destString); destButton.setActionCommand(destString); destButton.addActionListener(new DestListener()); // Create the save button. We use the image from the JLF // Graphics Repository (but we extracted it from the jar). saveButton = new JButton(saveString); saveButton.setActionCommand(saveString); saveButton.addActionListener(new SaveListener()); URL imageURL = getClass().getResource(greenButtonIcon); ImageIcon greenSquare = new ImageIcon(imageURL); startButton = new JButton("Start", greenSquare); startButton.setSize(60, 20); startButton.setHorizontalTextPosition(AbstractButton.LEADING); startButton.setActionCommand("Start"); startButton.addActionListener(new StartListener()); imageURL = getClass().getResource(redButtonIcon); ImageIcon redSquare = new ImageIcon(imageURL); stopButton = new JButton("Stop", redSquare); stopButton.setSize(60, 20); stopButton.setHorizontalTextPosition(AbstractButton.LEADING); stopButton.setActionCommand("Stop"); stopButton.addActionListener(new StopListener()); copyButton = new JRadioButton("Copy"); copyButton.setActionCommand("Copy"); copyButton.setSelected(true); copyButton.addActionListener(new RadioListener()); moveButton = new JRadioButton("Move"); moveButton.setActionCommand("Move"); moveButton.addActionListener(new RadioListener()); ButtonGroup group = new ButtonGroup(); group.add(copyButton); group.add(moveButton); // For layout purposes, put the buttons in a separate panel JPanel optionPanel = new JPanel(); GroupLayout layout = new GroupLayout(optionPanel); optionPanel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout.createSequentialGroup().addComponent(copyButton).addComponent(moveButton)); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(copyButton) .addComponent(moveButton))); JPanel buttonPanel = new JPanel(); // use FlowLayout layout = new GroupLayout(buttonPanel); buttonPanel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(openButton) .addComponent(optionPanel)) .addComponent(destButton) .addComponent(startButton) .addComponent(stopButton) // .addComponent(saveButton) ); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(openButton) .addComponent(destButton) .addComponent(startButton) .addComponent(stopButton) // .addComponent(saveButton) ) .addComponent(optionPanel)); buttonPanel.add(optionPanel); /* buttonPanel.add(openButton); buttonPanel.add(destButton); buttonPanel.add(startButton); buttonPanel.add(stopButton); buttonPanel.add(saveButton); buttonPanel.add(listLabel); buttonPanel.add(copyButton); buttonPanel.add(moveButton); */ destButton.setEnabled(false); startButton.setEnabled(false); stopButton.setEnabled(false); // Add the buttons and the log to this panel. // add(logScrollPane, BorderLayout.CENTER); JLabel listLabel = new JLabel("Monitored Directory:"); listLabel.setLabelFor(list); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener(this); list.setVisibleRowCount(8); JScrollPane listScrollPane = new JScrollPane(list); JPanel listPane = new JPanel(); listPane.setLayout(new BorderLayout()); listPane.add(listLabel, BorderLayout.PAGE_START); listPane.add(listScrollPane, BorderLayout.CENTER); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); // monitored, destination, waitInt, check destination = new JLabel("Destination Directory: "); waitField = new JFormattedTextField(); // waitField.setValue(240); waitField.setEditable(false); waitField.addPropertyChangeListener(new FormattedTextListener()); waitInt = new JLabel("Wait Interval (in minutes)"); // waitInt.setLabelFor(waitField); checkField = new JFormattedTextField(); checkField.setSize(1, 10); // checkField.setValue(60); checkField.setEditable(false); checkField.addPropertyChangeListener(new FormattedTextListener()); check = new JLabel("Check Interval (in minutes)"); // check.setLabelFor(checkField); fireButton = new JButton(fireString); fireButton.setActionCommand(fireString); fireButton.addActionListener(new FireListener()); JPanel fieldPane = new JPanel(); // fieldPane.add(destField); layout = new GroupLayout(fieldPane); fieldPane.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitInt) .addComponent(check)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitField, 60, 60, 60) .addComponent(checkField, 60, 60, 60))); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(waitInt) .addComponent(waitField)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(check) .addComponent(checkField))); JPanel labelPane = new JPanel(); labelPane.setLayout(new BorderLayout()); labelPane.add(destination, BorderLayout.PAGE_START); labelPane.add(fieldPane, BorderLayout.CENTER); layout = new GroupLayout(labelPane); labelPane.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(destination) .addComponent(fieldPane))); layout.setVerticalGroup( layout.createSequentialGroup().addComponent(destination).addComponent(fieldPane)); // labelPane.add(destination); // labelPane.add(fieldPane); try { // Read from disk using FileInputStream FileInputStream f_in = new FileInputStream(LOG_DIRECTORY + "\\save.data"); // Read object using ObjectInputStream ObjectInputStream obj_in = new ObjectInputStream(f_in); // Read an object directoryList = (directoryStorage) obj_in.readObject(); ERROR_LOG_NAME = (String) obj_in.readObject(); MOVE_LOG_NAME = (String) obj_in.readObject(); if (ERROR_LOG_NAME instanceof String) { printer.changeErrorLogName(ERROR_LOG_NAME); } if (MOVE_LOG_NAME instanceof String) { printer.changeMoveLogName(MOVE_LOG_NAME); } if (directoryList instanceof directoryStorage) { System.out.println("found object"); // directoryList = (directoryStorage) obj; Iterator<Directory> directories = directoryList.getDirectories(); Directory d; while (directories.hasNext()) { d = directories.next(); try { listModel.addElement(d.getDirectory().toRealPath()); } catch (IOException x) { printer.printError(x.toString()); } int index = list.getSelectedIndex(); if (index == -1) { list.setSelectedIndex(0); } index = list.getSelectedIndex(); Directory dir = directoryList.getDirectory(index); destButton.setEnabled(true); checkField.setValue(dir.getInterval()); waitField.setValue(dir.getWaitInterval()); checkField.setEditable(true); waitField.setEditable(true); // directoryList.addNewDirectory(d); // try { // listModel.addElement(d.getDirectory().toString()); // } catch (IOException x) { // printer.printError(x.toString()); // } // timer = new Timer(); // timer.schedule(new CopyTask(d.directory, d.destination, d.getWaitInterval(), printer, // d.copy), 0, d.getInterval()); } } else { System.out.println("did not find object"); } obj_in.close(); } catch (ClassNotFoundException x) { printer.printError(x.getLocalizedMessage()); System.err.format("Unable to read"); } catch (IOException y) { printer.printError(y.getLocalizedMessage()); } // Layout the text fields in a panel. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(buttonPanel, BorderLayout.PAGE_START); add(listPane, BorderLayout.LINE_START); // add(destListScrollPane, BorderLayout.CENTER); add(fieldPane, BorderLayout.LINE_END); add(labelPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
private JPanel createRulesPanel() { JPanel panel = new JPanel(); panel.addAncestorListener(new EventHandler()); panel.setBorder(BorderFactory.createEtchedBorder()); GroupLayout layout = new GroupLayout(panel); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); panel.setLayout(layout); GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup(); GroupLayout.ParallelGroup left = layout.createParallelGroup(); left.addComponent(numberOfRoundsLabel); left.addComponent(gunCoolingRateLabel); left.addComponent(inactivityTimeLabel); left.addComponent(sentryBorderSizeLabel); left.addComponent(hideEnemyNamesLabel); leftToRight.addGroup(left); GroupLayout.ParallelGroup right = layout.createParallelGroup(); right.addComponent(getNumberOfRoundsTextField()); right.addComponent(getGunCoolingRateTextField()); right.addComponent(getInactivityTimeTextField()); right.addComponent(getSentryBorderSizeTextField()); right.addComponent(hideEnemyNamesCheckBox); leftToRight.addGroup(right); GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup(); GroupLayout.ParallelGroup row0 = layout.createParallelGroup(Alignment.BASELINE); row0.addComponent(numberOfRoundsLabel); row0.addComponent(numberOfRoundsTextField); topToBottom.addGroup(row0); GroupLayout.ParallelGroup row1 = layout.createParallelGroup(Alignment.BASELINE); row1.addComponent(gunCoolingRateLabel); row1.addComponent(getGunCoolingRateTextField()); topToBottom.addGroup(row1); GroupLayout.ParallelGroup row2 = layout.createParallelGroup(Alignment.BASELINE); row2.addComponent(inactivityTimeLabel); row2.addComponent(inactivityTimeTextField); topToBottom.addGroup(row2); GroupLayout.ParallelGroup row3 = layout.createParallelGroup(Alignment.BASELINE); row3.addComponent(sentryBorderSizeLabel); row3.addComponent(sentryBorderSizeTextField); topToBottom.addGroup(row3); GroupLayout.ParallelGroup row4 = layout.createParallelGroup(Alignment.CENTER); row4.addComponent(hideEnemyNamesLabel); row4.addComponent(hideEnemyNamesCheckBox); topToBottom.addGroup(row4); layout.setHorizontalGroup(leftToRight); layout.setVerticalGroup(topToBottom); return panel; }