javax.swing.JButton#setHorizontalTextPosition ( )源码实例Demo

下面列出了javax.swing.JButton#setHorizontalTextPosition ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jts   文件: JTSTestBuilderToolBar.java
private JButton createButton(String toolTipText, 
    ImageIcon icon, 
    java.awt.event.ActionListener actionListener)
{
  JButton btn = new JButton();
  btn.setMargin(new Insets(0, 0, 0, 0));
  btn.setPreferredSize(new Dimension(30, 30));
  btn.setIcon(icon);
  btn.setMinimumSize(new Dimension(30, 30));
  btn.setVerticalTextPosition(SwingConstants.BOTTOM);
  btn.setSelected(false);
  btn.setToolTipText(toolTipText);
  btn.setHorizontalTextPosition(SwingConstants.CENTER);
  btn.setFont(new java.awt.Font("SansSerif", 0, 10));
  btn.setMaximumSize(new Dimension(30, 30));
  btn.addActionListener(actionListener);
  return btn;
}
 
源代码2 项目: WorldGrower   文件: StartScreen.java
private void addCreditsButton() {
	JButton btnCredits = JButtonFactory.createButton("Credits", IconUtils.getCreditsIcon(), imageInfoReader, soundIdReader);
	btnCredits.setHorizontalAlignment(SwingConstants.LEFT);
	btnCredits.setHorizontalTextPosition(SwingConstants.RIGHT);
	btnCredits.setToolTipText("Credits");
	btnCredits.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			try {
				CreditsDialog creditsDialog = new CreditsDialog(imageInfoReader, soundIdReader);
				creditsDialog.showMe();
			} catch (Exception e1) {
				ExceptionHandler.handle(e1);
			}
		}
	});
	frame.addComponent(btnCredits);
	SwingUtils.setBoundsAndCenterHorizontally(btnCredits, BUTTON_LEFT, 360, BUTTON_WIDTH, BUTTON_HEIGHT);
}
 
源代码3 项目: DroidUIBuilder   文件: SwitchablePane.java
private JButton createImageButton(String text, final boolean usedForPageButton)
{
	JButton btn = new JButton(text){
		public void paintComponent(Graphics g) {
			super.paintComponent(g);
			// 画选中时的装饰小图
			if(usedForPageButton 
					// 条件是本按钮就是当前正在显示的card所对应的顺序按钮
					&& (currrentCardIndex == Integer.parseInt(this.getText())))
			{
				g.drawImage(smallIconForCurrrentCard.getImage()
						, this.getWidth() - smallIconForCurrrentCard.getIconWidth() -1, 1
						, smallIconForCurrrentCard.getIconWidth(), smallIconForCurrrentCard.getIconHeight(), null);
			}
		}
	};
	btn.setHorizontalTextPosition(JButton.CENTER);
	btn.setMargin(new Insets(0,0,0,0));
	btn.setBorder(null);
	btn.setContentAreaFilled(false);
	btn.setFocusPainted(false);
	return btn;
}
 
源代码4 项目: nordpos   文件: Place.java
public void readValues(DataRead dr) throws BasicException {
    m_sId = dr.getString(1);
    m_sName = dr.getString(2);
    m_ix = dr.getInt(3).intValue();
    m_iy = dr.getInt(4).intValue();
    m_sfloor = dr.getString(5);
    
    m_bPeople = false;
    m_btn = new JButton();

    m_btn.setFocusPainted(false);
    m_btn.setFocusable(false);
    m_btn.setRequestFocusEnabled(false);
    m_btn.setHorizontalTextPosition(SwingConstants.CENTER);
    m_btn.setVerticalTextPosition(SwingConstants.BOTTOM);            
    m_btn.setIcon(ICO_FRE);
    m_btn.setText(m_sName);
}
 
源代码5 项目: nordpos   文件: JProductsSelector.java
public void addProduct(Image img, String name, ActionListener al) {
    
    JButton btn = new JButton();
    btn.applyComponentOrientation(getComponentOrientation());
    btn.setText(name);
    btn.setFont(btn.getFont().deriveFont((float)24));
    btn.setIcon(new ImageIcon(img));
    btn.setFocusPainted(false);
    btn.setFocusable(false);
    btn.setRequestFocusEnabled(false);
    btn.setHorizontalTextPosition(SwingConstants.CENTER);
    btn.setVerticalTextPosition(SwingConstants.BOTTOM);
    btn.setMargin(new Insets(2, 2, 2, 2));
    btn.setMaximumSize(new Dimension(80, 70));
    btn.setPreferredSize(new Dimension(80, 70));
    btn.setMinimumSize(new Dimension(80, 70));
    btn.addActionListener(al);
    flowpanel.add(btn);        
}
 
源代码6 项目: marathonv5   文件: ButtonDemo.java
public ButtonDemo() {
    ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
    ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
    ImageIcon rightButtonIcon = createImageIcon("images/left.gif");

    b1 = new JButton("Disable middle button", leftButtonIcon);
    b1.setVerticalTextPosition(AbstractButton.CENTER);
    b1.setHorizontalTextPosition(AbstractButton.LEADING); // aka LEFT, for
                                                          // left-to-right
                                                          // locales
    b1.setMnemonic(KeyEvent.VK_D);
    b1.setActionCommand("disable");

    b2 = new JButton("Middle button", middleButtonIcon);
    b2.setVerticalTextPosition(AbstractButton.BOTTOM);
    b2.setHorizontalTextPosition(AbstractButton.CENTER);
    b2.setMnemonic(KeyEvent.VK_M);

    b3 = new JButton("Enable middle button", rightButtonIcon);
    // Use the default text position of CENTER, TRAILING (RIGHT).
    b3.setMnemonic(KeyEvent.VK_E);
    b3.setActionCommand("enable");
    b3.setEnabled(false);

    // Listen for actions on buttons 1 and 3.
    b1.addActionListener(this);
    b3.addActionListener(this);

    b1.setToolTipText("Click this button to disable the middle button.");
    b2.setToolTipText("This middle button does nothing when you click it.");
    b3.setToolTipText("Click this button to enable the middle button.");

    // Add Components to this container, using the default FlowLayout.
    add(b1);
    add(b2);
    add(b3);
}
 
源代码7 项目: ios-image-util   文件: MainFrame.java
/**
 * Set preferences to Menu button.
 *
 * @param button
 * @param foregroundColor
 * @param backgroundColor
 * @param font
 * @return
 */
private JButton initMenuButton(JButton button, Color foregroundColor, Color backgroundColor, Font font) {
	button.setBackground(backgroundColor);
	button.setForeground(foregroundColor);
	button.setBorderPainted(false);
	button.setFocusPainted(false);
	button.setHorizontalTextPosition(SwingConstants.CENTER);
	button.setVerticalTextPosition(SwingConstants.BOTTOM);
	button.setFont(font);
	button.setMargin(new Insets(2, 16, 2, 16));
	button.setOpaque(true);
	button.setDoubleBuffered(true);
	button.setRolloverEnabled(true);
	return button;
}
 
private JButton create(String text) {
    JButton button = new JButton();
    button.setIcon(Utils.getIconByResourceName("/ui/resources/dock/" + text.toLowerCase()));
    button.setActionCommand(text);
    button.setHorizontalTextPosition(SwingConstants.CENTER);
    button.addActionListener(this);
    return button;
}
 
源代码9 项目: visualvm   文件: TransparentToolBar.java
private JButton createActionComponent(Action a) {
    JButton b = new JButton();
    if (a != null && (a.getValue(Action.SMALL_ICON) != null ||
                      a.getValue(Action.LARGE_ICON_KEY) != null)) {
        b.setHideActionText(true);
    }
    b.setHorizontalTextPosition(JButton.CENTER);
    b.setVerticalTextPosition(JButton.BOTTOM);
    b.setAction(a);
    return b;
}
 
源代码10 项目: OpERP   文件: StandardButtonHelper.java
public static JButton SetStandardSizeForButton(JButton btn){
	btn.setMaximumSize(new Dimension(95, 95));
	btn.setMinimumSize(new Dimension(95,95));
	btn.setHorizontalTextPosition(SwingConstants.CENTER);
	btn.setVerticalTextPosition(SwingConstants.BOTTOM);
	btn.setFont(new Font("Arial", Font.PLAIN, 10));
	return btn;
}
 
源代码11 项目: WorldGrower   文件: StartScreen.java
private void addLoadButton() {
	JButton btnLoadGame = JButtonFactory.createButton("Load Game", IconUtils.getLoadIcon(), imageInfoReader, soundIdReader);
	btnLoadGame.setHorizontalAlignment(SwingConstants.LEFT);
	btnLoadGame.setHorizontalTextPosition(SwingConstants.RIGHT);
	btnLoadGame.setToolTipText("Loads a game");
	btnLoadGame.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			LoadSaveDialog loadSaveDialog = new LoadSaveDialog(StartScreen.this, LoadSaveMode.LOAD, imageInfoReader, soundIdReader);
			loadSaveDialog.showMe();
		}
	});
	frame.addComponent(btnLoadGame);
	SwingUtils.setBoundsAndCenterHorizontally(btnLoadGame, BUTTON_LEFT, 150, BUTTON_WIDTH, BUTTON_HEIGHT);
}
 
源代码12 项目: nordpos   文件: JPaymentCashPos.java
public void addButton(String image, double amount) {
    JButton btn = new JButton();
    btn.setIcon(new ImageIcon(tnbbutton.getThumbNailText(dlSystem.getResourceAsImage(image), Formats.CURRENCY.formatValue(amount))));
    btn.setFocusPainted(false);
    btn.setFocusable(false);
    btn.setRequestFocusEnabled(false);
    btn.setHorizontalTextPosition(SwingConstants.CENTER);
    btn.setVerticalTextPosition(SwingConstants.BOTTOM);
    btn.setMargin(new Insets(2, 2, 2, 2));
    btn.addActionListener(new AddAmount(amount));
    jPanel6.add(btn);  
}
 
源代码13 项目: WorldGrower   文件: StartScreen.java
private void addExitButton() {
	JButton btnExit = JButtonFactory.createButton("Exit", IconUtils.getExitIcon(), imageInfoReader, soundIdReader);
	btnExit.setHorizontalAlignment(SwingConstants.LEFT);
	btnExit.setHorizontalTextPosition(SwingConstants.RIGHT);
	btnExit.setToolTipText("Exits program");
	btnExit.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			System.exit(0);
		}
	});
	frame.addComponent(btnExit);
	SwingUtils.setBoundsAndCenterHorizontally(btnExit, BUTTON_LEFT, 430, BUTTON_WIDTH, BUTTON_HEIGHT);
}
 
源代码14 项目: AppleCommander   文件: SwingAppleCommander.java
/**
 * Launch SwingAppleCommander.
 */
public void launch() {
	JMenuBar menuBar = createMenuBar();
	JToolBar toolBar = new JToolBar();
	JPanel topPanel = new JPanel(new BorderLayout());
	tabPane = new JTabbedPane(JTabbedPane.TOP);
	topPanel.add(menuBar,BorderLayout.NORTH);
	topPanel.add(toolBar,BorderLayout.SOUTH);
	JButton aButton = new JButton(textBundle.get("OpenButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/opendisk.gif")))); //$NON-NLS-1$
	aButton.setToolTipText(textBundle.get("SwtAppleCommander.OpenDiskImageTooltip")); //$NON-NLS-1$
	aButton.setHorizontalTextPosition(JLabel.CENTER);
	aButton.setVerticalTextPosition(JLabel.BOTTOM);
    aButton.addActionListener(this);
	toolBar.add(aButton);
	JButton aButton2 = new JButton(textBundle.get("CreateButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/newdisk.gif")))); //$NON-NLS-1$
	aButton2.setToolTipText(textBundle.get("SwtAppleCommander.CreateDiskImageTooltip")); //$NON-NLS-1$
	aButton2.setHorizontalTextPosition(JLabel.CENTER);
	aButton2.setVerticalTextPosition(JLabel.BOTTOM);
    aButton2.addActionListener(this);
	toolBar.add(aButton2);
	JButton aButton3 = new JButton(textBundle.get("CompareButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/comparedisks.gif")))); //$NON-NLS-1$
	aButton3.setToolTipText(textBundle.get("SwtAppleCommander.CompareDiskImageTooltip")); //$NON-NLS-1$
	aButton3.setHorizontalTextPosition(JLabel.CENTER);
	aButton3.setVerticalTextPosition(JLabel.BOTTOM);
    aButton3.addActionListener(this);
	toolBar.add(aButton3);
	JButton aButton4 = new JButton(textBundle.get("AboutButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/about.gif")))); //$NON-NLS-1$
	aButton4.setToolTipText(textBundle.get("SwtAppleCommander.AboutTooltip")); //$NON-NLS-1$
	aButton4.setHorizontalTextPosition(JLabel.CENTER);
	aButton4.setVerticalTextPosition(JLabel.BOTTOM);
    aButton4.addActionListener(this);
	toolBar.add(aButton4);
	SwingAppleCommander application = new SwingAppleCommander();
	application.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/diskicon.gif"))); //$NON-NLS-1$
	application.setTitle(textBundle.get("SwtAppleCommander.AppleCommander"));

	titleLabel = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/AppleCommanderLogo.jpg"))));

	addTitleTabPane();
	application.getContentPane().add(topPanel, BorderLayout.NORTH);
	application.getContentPane().add(tabPane, BorderLayout.CENTER);
	application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

	application.pack();
	application.setVisible(true);
   }
 
源代码15 项目: audiveris   文件: InterBoard.java
/**
 * Define the layout for InterBoard specific fields.
 */
private void defineLayout ()
{
    final CellConstraints cst = new CellConstraints();

    // Layout
    int r = 1; // -----------------------------

    // Shape Icon (start, spans several rows) + grade + Deassign button
    builder.add(shapeIcon, cst.xywh(1, r, 1, 5));

    builder.add(grade.getLabel(), cst.xy(5, r));
    builder.add(grade.getField(), cst.xy(7, r));

    JButton deassignButton = new JButton(deassignAction);
    deassignButton.setHorizontalTextPosition(SwingConstants.LEFT);
    deassignButton.setHorizontalAlignment(SwingConstants.RIGHT);
    deassignAction.setEnabled(false);
    builder.add(deassignButton, cst.xyw(9, r, 3));

    r += 2; // --------------------------------

    builder.add(shapeField.getField(), cst.xyw(7, r, 5));

    r += 2; // --------------------------------

    roleCombo.getField().setMaximumRowCount(TextRole.values().length);
    roleCombo.addActionListener(paramAction);
    roleCombo.setVisible(false);
    builder.add(roleCombo.getField(), cst.xyw(3, r, 4));

    // Text field
    textField.getField().setHorizontalAlignment(JTextField.LEFT);
    textField.setVisible(false);
    builder.add(textField.getField(), cst.xyw(7, r, 5));

    r += 2; // --------------------------------

    builder.add(details, cst.xyw(1, r, 11));

    // Needed to process user input when RETURN/ENTER is pressed
    getComponent().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
            KeyStroke.getKeyStroke("ENTER"),
            "TextAction");
    getComponent().getActionMap().put("TextAction", paramAction);
}
 
源代码16 项目: audiveris   文件: SampleBoard.java
/**
 * Define the layout for SampleBoard specific fields.
 */
private void defineLayout ()
{
    final CellConstraints cst = new CellConstraints();

    // Layout
    int r = 1; // -----------------------------

    JButton removeButton = new JButton(controller.getRemoveAction());
    removeButton.setHorizontalTextPosition(SwingConstants.LEFT);
    removeButton.setHorizontalAlignment(SwingConstants.RIGHT);
    removeAction.setEnabled(false);
    builder.add(removeButton, cst.xyw(5, r, 3));

    assignButton = new JButton(assignAction);
    assignButton.setHorizontalTextPosition(SwingConstants.LEFT);
    assignButton.setHorizontalAlignment(SwingConstants.RIGHT);
    assignAction.setEnabled(false);
    builder.add(assignButton, cst.xyw(9, r, 3));

    r += 2; // --------------------------------

    // Shape Icon (start, spans several rows)
    builder.add(shapeIcon, cst.xywh(3, r, 1, 9));

    builder.add(sheetName.getLabel(), cst.xy(1, r));
    builder.add(sheetName.getField(), cst.xyw(3, r, 9));

    r += 2; // --------------------------------

    builder.add(shapeField.getLabel(), cst.xy(5, r));
    builder.add(shapeField.getField(), cst.xyw(7, r, 5));

    r += 2; // --------------------------------

    builder.add(iLine.getLabel(), cst.xy(5, r));
    builder.add(iLine.getField(), cst.xy(7, r));

    builder.add(width.getLabel(), cst.xy(9, r));
    builder.add(width.getField(), cst.xy(11, r));

    r += 2; // --------------------------------

    builder.add(weight.getLabel(), cst.xy(5, r));
    builder.add(weight.getField(), cst.xy(7, r));

    builder.add(height.getLabel(), cst.xy(9, r));
    builder.add(height.getField(), cst.xy(11, r));

    r += 2; // --------------------------------

    builder.add(pitch.getLabel(), cst.xy(9, r));
    builder.add(pitch.getField(), cst.xy(11, r));
}
 
源代码17 项目: ChromeForensics   文件: MainPanel.java
private void initToolBar() {
    toolBar = new JToolBar();
    toolBar.setOrientation(JToolBar.HORIZONTAL);
    toolBar.setFloatable(false);
    toolBar.setPreferredSize(new Dimension(getWidth(), 40));

    manuallyLoadData = new JButton();
    manuallyLoadData.setIcon(Utils.createImageIcon("images/loaddata.png", "Load Data"));
    manuallyLoadData.setToolTipText("Manually locate the chrome data files folder.");
    toolBar.add(manuallyLoadData);

    autoLoadData = new JButton();
    autoLoadData.setIcon(Utils.createImageIcon("images/autosearch.png", "Auto Search and Load Data"));
    autoLoadData.setToolTipText("Automatically search and load chrome files.");
    toolBar.add(autoLoadData);

    toolBar.add(new JToolBar.Separator());

    exportTSV = new JButton("Export to");
    exportTSV.setIcon(Utils.createImageIcon("images/csv.png", "Export results to CSV"));
    exportTSV.setToolTipText("Export Results to CSV");
    exportTSV.setHorizontalTextPosition(SwingConstants.LEFT);
    exportTSV.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            ExportDialog export = new ExportDialog(ExportType.TSV);
            export.setVisible(true);
        }
    });
    toolBar.add(exportTSV);

    exportHTML = new JButton("Export to");
    exportHTML.setIcon(Utils.createImageIcon("images/html.png", "Export results to HTML"));
    exportHTML.setToolTipText("Export results to HTML.");
    exportHTML.setHorizontalTextPosition(SwingConstants.LEFT);
    toolBar.add(exportHTML);

    toolBar.add(new JToolBar.Separator());

    helpButton = new JButton();
    helpButton.setIcon(Utils.createImageIcon("images/help.png", "Need Help? Click Me!"));
    helpButton.setToolTipText("Need Help? Click Me!");
    toolBar.add(helpButton);

    aboutButton = new JButton();
    aboutButton.setIcon(Utils.createImageIcon("images/about.png", "About this tool!"));
    aboutButton.setToolTipText("About this tool!");
    toolBar.add(aboutButton);

    toolBar.add(new JToolBar.Separator());

    exitButton = new JButton();
    exitButton.setIcon(Utils.createImageIcon("images/exit.png", "Exit Application."));
    exitButton.setToolTipText("Exit Application");
    exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionEvent) {
            ChromeForensicsGui.getInstance().dispose();
        }
    });
    toolBar.add(exitButton);
}
 
/**
 * Updates the charts.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateCharts() {
	for (int i = 0; i < listOfChartPanels.size(); i++) {
		JPanel panel = listOfChartPanels.get(i);
		panel.removeAll();
		JFreeChart chartOrNull = getModel().getChartOrNull(i);
		if (chartOrNull != null) {
			final ChartPanel chartPanel = new ChartPanel(chartOrNull) {

				private static final long serialVersionUID = -6953213567063104487L;

				@Override
				public Dimension getPreferredSize() {
					return DIMENSION_CHART_PANEL_ENLARGED;
				}
			};
			chartPanel.setPopupMenu(null);
			chartPanel.setBackground(COLOR_TRANSPARENT);
			chartPanel.setOpaque(false);
			chartPanel.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
			panel.add(chartPanel, BorderLayout.CENTER);

			JPanel openChartPanel = new JPanel(new GridBagLayout());
			openChartPanel.setOpaque(false);

			GridBagConstraints gbc = new GridBagConstraints();
			gbc.anchor = GridBagConstraints.CENTER;
			gbc.fill = GridBagConstraints.NONE;
			gbc.weightx = 1.0;
			gbc.weighty = 1.0;

			JButton openChartButton = new JButton(OPEN_CHART_ACTION);
			openChartButton.setOpaque(false);
			openChartButton.setContentAreaFilled(false);
			openChartButton.setBorderPainted(false);
			openChartButton.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
			openChartButton.setHorizontalAlignment(SwingConstants.LEFT);
			openChartButton.setHorizontalTextPosition(SwingConstants.LEFT);
			openChartButton.setIcon(null);
			Font font = openChartButton.getFont();
			Map attributes = font.getAttributes();
			attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
			openChartButton.setFont(font.deriveFont(attributes).deriveFont(10.0f));

			openChartPanel.add(openChartButton, gbc);

			panel.add(openChartPanel, BorderLayout.SOUTH);
		}
		panel.revalidate();
		panel.repaint();
	}
}
 
/**
 * Updates the charts.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateCharts() {
	for (int i = 0; i < listOfChartPanels.size(); i++) {
		JPanel panel = listOfChartPanels.get(i);
		panel.removeAll();
		final ChartPanel chartPanel = new ChartPanel(getModel().getChartOrNull(i)) {

			private static final long serialVersionUID = -6953213567063104487L;

			@Override
			public Dimension getPreferredSize() {
				return DIMENSION_CHART_PANEL_ENLARGED;
			}
		};
		chartPanel.setPopupMenu(null);
		chartPanel.setBackground(COLOR_TRANSPARENT);
		chartPanel.setOpaque(false);
		chartPanel.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
		panel.add(chartPanel, BorderLayout.CENTER);

		JPanel openChartPanel = new JPanel(new GridBagLayout());
		openChartPanel.setOpaque(false);

		GridBagConstraints gbc = new GridBagConstraints();
		gbc.anchor = GridBagConstraints.CENTER;
		gbc.fill = GridBagConstraints.NONE;
		gbc.weightx = 1.0;
		gbc.weighty = 1.0;

		JButton openChartButton = new JButton(OPEN_CHART_ACTION);
		openChartButton.setOpaque(false);
		openChartButton.setContentAreaFilled(false);
		openChartButton.setBorderPainted(false);
		openChartButton.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
		openChartButton.setHorizontalAlignment(SwingConstants.LEFT);
		openChartButton.setHorizontalTextPosition(SwingConstants.LEFT);
		openChartButton.setIcon(null);
		Font font = openChartButton.getFont();
		Map attributes = font.getAttributes();
		attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
		openChartButton.setFont(font.deriveFont(attributes).deriveFont(10.0f));

		openChartPanel.add(openChartButton, gbc);

		panel.add(openChartPanel, BorderLayout.SOUTH);
		panel.revalidate();
		panel.repaint();
	}
}
 
源代码20 项目: Math-Game   文件: OptionMenu.java
public OptionMenu(MathGame mathGame) {
	this.mathGame = mathGame;
	this.tm = mathGame.getTypeManager();
	
	this.setLayout(new GridBagLayout());
	// this.setLayout(new FlowLayout(FlowLayout.CENTER));
	gbc = new GridBagConstraints();
	 
	// Set size
	Dimension size = getPreferredSize();
	size.width = mathGame.getWidth();
	size.height = mathGame.getHeight();
	setPreferredSize(size);
	
	// Image initialization
	background = new ImageIcon(OptionMenu.class.getResource(BACKGROUND_FILE));
	buttonImage = new ImageIcon(OptionMenu.class.getResource(BUTTON_IMAGE_FILE));
	buttonRollOverImage = new ImageIcon(OptionMenu.class.getResource(BUTTON_ROLLOVER_IMAGE_FILE));
	buttonPressedImage = new ImageIcon(OptionMenu.class.getResource(BUTTON_PRESSED_IMAGE_FILE));
	
	// Button creation
	buttonMap = new HashMap<String, JToggleButton>();
	initModes();
	initTypes();
	initDiffs();
	
	// Default selections
	modes.get(0).setSelected(true);
	types.get(0).setSelected(true);
	diffs.get(0).setSelected(true);
	mathGame.setGameState(GameState.PRACTICE);
	
	play = new JButton("Play");
	play.setFont(eurostile24);
    play.setHorizontalTextPosition(JButton.CENTER);
    play.setVerticalTextPosition(JButton.CENTER);
    play.setBorderPainted(false);
    play.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
	play.addActionListener(this);
	
	try {
	    play.setIcon(buttonImage);
	    play.setRolloverIcon(buttonRollOverImage);
	    play.setPressedIcon(buttonPressedImage);
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	
	gbc.insets = new Insets(5, 5, 5, 5);
	gbc.gridwidth = 3;
	gbc.gridheight = 3;
	gbc.gridx = 0;
	gbc.gridy = 0;
	add(modePanel, gbc);
	gbc.gridx = 4;
	gbc.gridy = 0;
	gbc.gridwidth = 3;
	gbc.gridheight = 3;
	add(typePanel, gbc);
	gbc.gridx = 8;
	gbc.gridy = 0;
	gbc.weighty = 1;
	gbc.gridwidth = 3;
	gbc.gridheight = 3;
	add(diffPanel, gbc);
	gbc.gridx = 4;
	gbc.gridy = 3;
	add(play, gbc);
}