本文整理汇总了Java中javax.swing.JButton.setText方法的典型用法代码示例。如果您正苦于以下问题:Java JButton.setText方法的具体用法?Java JButton.setText怎么用?Java JButton.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JButton
的用法示例。
在下文中一共展示了JButton.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createButtons
import javax.swing.JButton; //导入方法依赖的package包/类
void createButtons() {
for (int i = 0; i < chars.length; i++) {
JButton button = new JButton(new CharAction(chars[i]));
button.setMaximumSize(new Dimension(50, 22));
//button.setMinimumSize(new Dimension(22, 22));
button.setPreferredSize(new Dimension(30, 22));
button.setRequestFocusEnabled(false);
button.setFocusable(false);
button.setBorderPainted(false);
button.setOpaque(false);
button.setMargin(new Insets(0,0,0,0));
button.setFont(new Font("serif", 0, 14));
if (i == chars.length-1) {
button.setText("nbsp");
button.setFont(new Font("Dialog",0,10));
button.setMargin(new Insets(0,0,0,0));
}
this.add(button, null);
}
}
示例2: erzeugeRuecknahmeButton
import javax.swing.JButton; //导入方法依赖的package包/类
/**
* Erzeuge den Rücknahme-Button.
*/
private void erzeugeRuecknahmeButton()
{
JPanel buttonPanel = new JPanel();
_ruecknahmePanel.add(buttonPanel, BorderLayout.SOUTH);
buttonPanel.setPreferredSize(new java.awt.Dimension(-1, 110));
buttonPanel.setSize(-1, -1);
buttonPanel.setBackground(UIConstants.BACKGROUND_COLOR);
_ruecknahmeButton = new JButton();
buttonPanel.add(_ruecknahmeButton);
_ruecknahmeButton.setText("zurücknehmen");
_ruecknahmeButton.setPreferredSize(new java.awt.Dimension(140, 100));
_ruecknahmeButton.setSize(-1, -1);
_ruecknahmeButton.setEnabled(false);
_ruecknahmeButton.setFont(UIConstants.BUTTON_FONT);
}
示例3: makeButton
import javax.swing.JButton; //导入方法依赖的package包/类
/**
* Creates a button for toolbar.
*/
private JButton makeButton(String imageName, String actionCommand, String toolTipText, String altText) {
//Look for the image.
String imgLocation = "images/" + imageName + "16.png";
URL imageURL = PlotCanvas.class.getResource(imgLocation);
//Create and initialize the button.
JButton button = new JButton();
button.setActionCommand(actionCommand);
button.setToolTipText(toolTipText);
button.addActionListener(this);
if (imageURL != null) { //image found
button.setIcon(new ImageIcon(imageURL, altText));
} else { //no image found
button.setText(altText);
logger.error("Resource not found: {}", imgLocation);
}
return button;
}
示例4: makeNavigationButton
import javax.swing.JButton; //导入方法依赖的package包/类
protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {
// Look for the image.
String imgLocation = "images/" + imageName + ".gif";
URL imageURL = ToolBarDemo.class.getResource(imgLocation);
// Create and initialize the button.
JButton button = new JButton();
button.setActionCommand(actionCommand);
button.setToolTipText(toolTipText);
button.addActionListener(this);
if (imageURL != null) { // image found
button.setIcon(new ImageIcon(imageURL, altText));
} else { // no image found
button.setText(altText);
System.err.println("Resource not found: " + imgLocation);
}
return button;
}
示例5: erzeugeAusleihButton
import javax.swing.JButton; //导入方法依赖的package包/类
/**
* Erzeugt den Ausleih-Button.
*/
private void erzeugeAusleihButton()
{
JPanel _buttonPanel = new JPanel();
_ausleihePanel.add(_buttonPanel, BorderLayout.SOUTH);
_buttonPanel.setPreferredSize(new Dimension(-1, 110));
_buttonPanel.setSize(-1, -1);
_buttonPanel.setBackground(UIConstants.BACKGROUND_COLOR);
_ausleihButton = new JButton();
_buttonPanel.add(_ausleihButton);
_ausleihButton.setText("ausleihen");
_ausleihButton.setPreferredSize(new Dimension(140, 100));
_ausleihButton.setSize(-1, -1);
_ausleihButton.setFont(UIConstants.BUTTON_FONT);
_ausleihButton.setEnabled(false);
}
示例6: getTableCellEditorComponent
import javax.swing.JButton; //导入方法依赖的package包/类
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
currentClass = (String)value;
JButton btn = new JButton();
btn.setText(currentClass);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
classSelector.setClassSelected(currentClass);
classSelector.setVisible(true);
}
});
return btn;
}
示例7: getJButtonExample
import javax.swing.JButton; //导入方法依赖的package包/类
/**
* Gets an example JButton.
* @return the JButton example
*/
private JButton getJButtonExample() {
JButton myButton = new JButton();
myButton.setText("! My customized button !");
myButton.setToolTipText("This is the tool tip text of your customized toolbar button");
myButton.setSize(36, 36);
// --------------------------------------------------------------------
// Usually we took this Dimension and left the setText() empty !!
// myButton.setPreferredSize( new Dimension(26,26) );
// --------------------------------------------------------------------
myButton.setPreferredSize( new Dimension(170, 26) );
// --------------------------------------------------------------------
myButton.setIcon(GlobalInfo.getInternalImageIcon("Refresh.png"));
myButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("This event came from your customized toolbar-button !");
}
});
return myButton;
}
示例8: makeNavigationButton
import javax.swing.JButton; //导入方法依赖的package包/类
protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {
// Look for the image.
String imgLocation = "images/" + imageName + ".gif";
URL imageURL = ToolBarDemo2.class.getResource(imgLocation);
// Create and initialize the button.
JButton button = new JButton();
button.setActionCommand(actionCommand);
button.setToolTipText(toolTipText);
button.addActionListener(this);
if (imageURL != null) { // image found
button.setIcon(new ImageIcon(imageURL, altText));
} else { // no image found
button.setText(altText);
System.err.println("Resource not found: " + imgLocation);
}
return button;
}
示例9: createButtons
import javax.swing.JButton; //导入方法依赖的package包/类
/**
* @return a {@link JPanel} with {@link JButton}s to manipulate the network
* table: Move up, move down, add, remove.
*/
private JPanel createButtons() {
JPanel bpanel = new JPanel();
bpanel.setLayout(new BoxLayout(bpanel, BoxLayout.PAGE_AXIS));
ActionListener listener = new ButtonHandler();
JButton[] jbuttons = new JButton[4];
String[] buttons = {
UP_LBL, UP_TIP, UP_ACTN,
DOWN_LBL, DOWN_TIP, DOWN_ACTN,
ADD_LBL, ADD_TIP, ADD_ACTN,
REMOVE_LBL, REMOVE_TIP, REMOVE_ACTN
};
for (int i = 0; i < jbuttons.length; i++) {
JButton button = new JButton();
button.setText(buttons[i*3]);
button.setToolTipText(buttons[i*3+1]);
button.setActionCommand(buttons[i*3+2]);
button.addActionListener(listener);
button.setMaximumSize(new Dimension(
Short.MAX_VALUE, button.getPreferredSize().height));
bpanel.add(button);
jbuttons[i] = button;
if (i != jbuttons.length - 1) {
bpanel.add(Box.createVerticalStrut(PADDING));
}
}
this.moveUp = jbuttons[0];
this.moveDown = jbuttons[1];
this.add = jbuttons[2];
this.remove = jbuttons[3];
return bpanel;
}
示例10: initToolbar
import javax.swing.JButton; //导入方法依赖的package包/类
private void initToolbar() {
Insets ins = actionsBar.getMargin();
JButton dummy = new JButton();
dummy.setBorderPainted(false);
dummy.setOpaque(false);
dummy.setText(null);
dummy.setIcon(new Icon() {
@Override
public int getIconHeight() {
return 16;
}
@Override
public int getIconWidth() {
return 16;
}
@SuppressWarnings(value = "empty-statement")
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
;
}
});
actionsBar.add(dummy);
Dimension buttonPref = dummy.getPreferredSize();
Dimension minDim = new Dimension(buttonPref.width + ins.left + ins.right, buttonPref.height + ins.top + ins.bottom);
actionsBar.setMinimumSize(minDim);
actionsBar.setPreferredSize(minDim);
actionsBar.remove(dummy);
actionsBar.setBorder(new RightBorder());
actionsBar.setBorderPainted(true);
}
示例11: fill
import javax.swing.JButton; //导入方法依赖的package包/类
private static BeanContext fill(BeanContext context) {
context.add(new JLabel("label"));
context.add(new JButton("button"));
JButton button = new JButton();
button.setText("another button");
context.add(button);
return context;
}
示例12: TextNotification
import javax.swing.JButton; //导入方法依赖的package包/类
public TextNotification() {
m_fromLabel = new JLabel();
m_titleLabel = new JLabel();
m_titleLabel.addMouseListener(new NotificationMouseAdapter(m_titleLabel));
m_subtitleArea = new JTextArea();
m_subtitleArea.addMouseListener(new NotificationMouseAdapter(m_titleLabel));
JPanel panelHeader = new JPanel();
panelHeader.setLayout(new BoxLayout(panelHeader, BoxLayout.PAGE_AXIS));
JButton dimissButton = new JButton();
dimissButton.setText("X");
final TextNotification me = this;
dimissButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
me.removeFromManager();
}
});
dimissButton.setOpaque(false);
dimissButton.setContentAreaFilled(false);
dimissButton.setBorderPainted(false);
dimissButton.setBounds((int) (this.getWidth() - dimissButton.getPreferredSize().getWidth()), 0, (int) dimissButton.getPreferredSize().getWidth(), (int) dimissButton.getPreferredSize().getHeight());
m_panel.add(dimissButton);
panelHeader.add(m_fromLabel);
panelHeader.add(m_titleLabel);
this.addComponent(panelHeader, BorderLayout.NORTH);
this.addComponent(m_subtitleArea, BorderLayout.CENTER);
}
示例13: addButton
import javax.swing.JButton; //导入方法依赖的package包/类
private void addButton(JPanel panel, String label, Command command)
{
JButton button = new JButton();
button.setText(label);
button.setActionCommand(command.name());
button.addActionListener(_actionListener);
panel.add(button);
}
示例14: createDataSourceSelectionButton
import javax.swing.JButton; //导入方法依赖的package包/类
private JButton createDataSourceSelectionButton(@SuppressWarnings("rawtypes") final DataSourceFactory factory) {
String label = DataImportWizardUtils.getFactoryLabel(factory);
String description = DataImportWizardUtils.getFactoryDescription(factory);
JButton typeSelectionButton = new JButton(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
enableDataSourceButtons(false);
// update the wizard by setting the selected factory
wizard.setDataSource(factory.createNew(), factory);
// switch to the next wizard step (location selection)
wizard.nextStep();
}
});
typeSelectionButton.setText(label);
typeSelectionButton.setToolTipText(description);
typeSelectionButton.setMinimumSize(TYPE_BUTTON_DIMENSION);
typeSelectionButton.setPreferredSize(TYPE_BUTTON_DIMENSION);
typeSelectionButton.setMaximumSize(TYPE_BUTTON_DIMENSION);
typeSelectionButton.setIcon(DataImportWizardUtils.getFactoryIcon(factory));
return typeSelectionButton;
}
示例15: activateButton
import javax.swing.JButton; //导入方法依赖的package包/类
public static void activateButton(JButton button, String text, ActionListener newListener) {
button.setText(text);
button.setEnabled(true);
for (ActionListener listener : Arrays.asList(button.getActionListeners())) {
button.removeActionListener(listener);
}
button.addActionListener(newListener);
}