jbutton可以设置id吗_Java JButton.setHorizontalTextPosition方法代碼示例

本文整理匯總了Java中javax.swing.JButton.setHorizontalTextPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java JButton.setHorizontalTextPosition方法的具體用法?Java JButton.setHorizontalTextPosition怎麽用?Java JButton.setHorizontalTextPosition使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JButton的用法示例。

在下文中一共展示了JButton.setHorizontalTextPosition方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: createButton

​點讚 3

import javax.swing.JButton; //導入方法依賴的package包/類

/**

* Helper method used to create a button inside a JPanel

* @param action action associated to that button

* @return created component

*/

private JComponent createButton(AbstractAction action) {

JPanel panel = new JPanel(); // Use gridbag as centers by default

JButton button = new JButton(action);

button.setHorizontalTextPosition(SwingConstants.CENTER);

button.setVerticalTextPosition(SwingConstants.BOTTOM);

button.setPreferredSize(new Dimension((int) (BUTTONSIZE * 3.5), (BUTTONSIZE * 2)));

button.addMouseListener(rollover);

if (action == buttonAction[3]) {

button.setVisible(false);

}

if (action == buttonAction[0]) {

button.setEnabled(false);

}

//if (action == buttonAction[2]) button.setEnabled(false);

//if (action == buttonAction[4]) button.setEnabled(false);

panel.add(button);

return panel;

}

開發者ID:max6cn,項目名稱:jmt,代碼行數:24,

示例2: createButton

​點讚 3

import javax.swing.JButton; //導入方法依賴的package包/類

/**

* Helper method used to create a button inside a JPanel

* @param action action associated to that button

* @return created component

*/

private JComponent createButton(AbstractAction action) {

JPanel panel = new JPanel(); // Use gridbag as centers by default

JButton button = new JButton(action);

button.setHorizontalTextPosition(SwingConstants.CENTER);

button.setVerticalTextPosition(SwingConstants.BOTTOM);

button.setPreferredSize(new Dimension((int) (BUTTONSIZE * 3.5), (BUTTONSIZE * 2)));

button.addMouseListener(rollover);

//if (action == buttonAction[4]) {

//button.setVisible(false);

//}

//if (action == buttonAction[0]) {

//button.setEnabled(false);

//}

//if (action == buttonAction[2]) button.setEnabled(false);

//if (action == buttonAction[4]) button.setEnabled(false);

panel.add(button);

return panel;

}

開發者ID:max6cn,項目名稱:jmt,代碼行數:24,

示例3: createButton

​點讚 3

import javax.swing.JButton; //導入方法依賴的package包/類

/**

* Helper method used to create a button inside a JPanel

* @param action action associated to that button

* @return created component

*/

private JComponent createButton(AbstractAction action) {

JPanel panel = new JPanel(); // Use gridbag as centers by default

JButton button = new JButton(action);

button.setHorizontalTextPosition(SwingConstants.CENTER);

button.setVerticalTextPosition(SwingConstants.BOTTOM);

button.setPreferredSize(new Dimension((int) (BUTTONSIZE * 3.5), (BUTTONSIZE * 2)));

button.addMouseListener(rollover);

if (action == buttonAction[3]) {

button.setVisible(false);

}

if (action == buttonAction[0]) {

button.setEnabled(false);

}

//if(action == buttonAction[2]) button.setEnabled(false);

//if(action == buttonAction[4]) button.setEnabled(false);

panel.add(button);

return panel;

}

開發者ID:HOMlab,項目名稱:QN-ACTR-Release,代碼行數:24,

示例4: createButton

​點讚 3

import javax.swing.JButton; //導入方法依賴的package包/類

/**

* Helper method used to create a button inside a JPanel

* @param action action associated to that button

* @return created component

*/

private JComponent createButton(AbstractAction action) {

JPanel panel = new JPanel(); // Use gridbag as centers by default

JButton button = new JButton(action);

button.setHorizontalTextPosition(SwingConstants.CENTER);

button.setVerticalTextPosition(SwingConstants.BOTTOM);

button.setPreferredSize(new Dimension((int) (BUTTONSIZE * 3.5), (BUTTONSIZE * 2)));

button.addMouseListener(rollover);

//if (action == buttonAction[4]) {

//button.setVisible(false);

//}

//if (action == buttonAction[0]) {

//button.setEnabled(false);

//}

//if(action == buttonAction[2]) button.setEnabled(false);

//if(action == buttonAction[4]) button.setEnabled(false);

panel.add(button);

return panel;

}

開發者ID:HOMlab,項目名稱:QN-ACTR-Release,代碼行數:24,

示例5: createButton

​點讚 2

import javax.swing.JButton; //導入方法依賴的package包/類

/**

* Helper method used to create a button inside a JPanel

* @param action action associated to that button

* @return created component

*/

private JComponent createButton(AbstractAction action) {

JPanel panel = new JPanel(); // Use gridbag as centers by default

JButton button = new JButton(action);

button.setHorizontalTextPosition(SwingConstants.CENTER);

button.setVerticalTextPosition(SwingConstants.BOTTOM);

button.setPreferredSize(new Dimension((int) (BUTTONSIZE * 3.5), (BUTTONSIZE * 2)));

button.addMouseListener(rollover);

panel.add(button);

return panel;

}

開發者ID:max6cn,項目名稱:jmt,代碼行數:16,

示例6: ButtonDemo

​點讚 2

import javax.swing.JButton; //導入方法依賴的package包/類

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);

}

開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:38,

示例7: generateControl

​點讚 2

import javax.swing.JButton; //導入方法依賴的package包/類

@Override

public JComponent generateControl()

{

field = new JTextField();

field.setMaximumSize(new Dimension(Short.MAX_VALUE, 20));

if( items.size() >= 1 )

{

field.setText(((Item) items.get(0)).getValue());

}

JButton browse = new JButton("Browse");

browse.setIcon(new ImageIcon(getClass().getResource("/images/browse.gif")));

browse.setHorizontalTextPosition(SwingConstants.RIGHT);

Dimension browseSize = browse.getPreferredSize();

browseSize.height = 20;

browse.setMaximumSize(browseSize);

browse.addActionListener(this);

JPanel group = new JPanel();

group.setLayout(new BoxLayout(group, BoxLayout.X_AXIS));

group.add(field);

group.add(Box.createRigidArea(new Dimension(5, 0)));

group.add(browse);

group.setAlignmentX(Component.LEFT_ALIGNMENT);

return group;

}

開發者ID:equella,項目名稱:Equella,代碼行數:29,

示例8: initialise

​點讚 2

import javax.swing.JButton; //導入方法依賴的package包/類

private void initialise()

{

currentText = getTextComponent();

popupButton = new JButton();

popupButton.addActionListener(new PopupListener());

popupButton.setIcon(new ArrowIcon(SwingConstants.SOUTH));

popupButton.setHorizontalTextPosition(SwingConstants.LEFT);

initialiseLayout("hidemode 3,insets 0,fill", "growx", true); //$NON-NLS-1$ //$NON-NLS-2$

switchLocale(null);

}

開發者ID:equella,項目名稱:Equella,代碼行數:13,

示例9: create

​點讚 2

import javax.swing.JButton; //導入方法依賴的package包/類

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;

}

開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:9,

示例10: prepareButton

​點讚 2

import javax.swing.JButton; //導入方法依賴的package包/類

void prepareButton(JButton btn) {

btn.setBorderPainted(false);

btn.setFocusPainted(false);

btn.setHorizontalAlignment(JButton.CENTER);

btn.setHorizontalTextPosition(JButton.CENTER);

btn.setVerticalTextPosition(JButton.BOTTOM);

}

開發者ID:kmarius,項目名稱:xdman,代碼行數:8,

示例11: updateCharts

​點讚 2

import javax.swing.JButton; //導入方法依賴的package包/類

/**

* 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();

}

}

開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:53,

示例12: ButtonHtmlDemo

​點讚 2

import javax.swing.JButton; //導入方法依賴的package包/類

public ButtonHtmlDemo() {

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);

Font font = b1.getFont().deriveFont(Font.PLAIN);

b1.setFont(font);

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.setFont(font);

b2.setForeground(new Color(0xffffdd));

b2.setVerticalTextPosition(AbstractButton.BOTTOM);

b2.setHorizontalTextPosition(AbstractButton.CENTER);

b2.setMnemonic(KeyEvent.VK_M);

b3 = new JButton("

Enable
" + " middle button", rightButtonIcon);

b3.setFont(font);

// 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);

}

開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:43,

示例13: launch

​點讚 2

import javax.swing.JButton; //導入方法依賴的package包/類

/**

* 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.gif"))));

addTitleTabPane();

application.getContentPane().add(topPanel, BorderLayout.NORTH);

application.getContentPane().add(tabPane, BorderLayout.CENTER);

application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

application.pack();

application.setVisible(true);

}

開發者ID:AppleCommander,項目名稱:AppleCommander,代碼行數:47,

注:本文中的javax.swing.JButton.setHorizontalTextPosition方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一:使用匿名内部类的形式进行设置       1.首先需要得到id,即必须清楚button的id值。        2.使用setOnClickListener,如下图所示    二:在XML文件中定义OnClick属性,在java代码中对应方法。       在button下加上如下代码android:onClick=skip(skip即为方法对应的名字,然后在java代码中在定义具体的方法)                 实现的结果如下: --------------------- 作者:xd1501013 来源:CSDN 原文:https://blog.csdn.net/xd15010130025/article/details/77604329 版权声明:本文为博主原创文章,转载请附上博文链接! Button按钮四种监听(二) 继续上次的,我们接下来要学习另外两种方式,三:Activity实现onClickListener接口;四:其他类实现onClickListener接口。    三:Activity实现onClickListener接口      1.直接在Activity上添加          public class MainActivity extends Activity implements OnClickListener{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=(Button)findViewById(R.id.button1); btn.setOnClickListener(this); } 再创建方法      public void onClick(View v) { // TODO 自动生成的方法存根 Log.i("tag", "点击了button按钮"); } 实现效果    四:其他类实现onClickListener接口       1.创建一个其他类 class mylistener implements OnClickListener{ @Override public void onClick(View v) { // TODO 自动生成的方法存根 Log.i("tag", "点击了button按钮"); } }      二: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=(Button)findViewById(R.id.button1); btn.setOnClickListener(new mylistener()); } 即可实现。 如果两个按钮怎么办????     用v.getId得到id值,然后用case来处理不同的情况.   --------------------- 作者:xd1501013 来源:CSDN 原文:https://blog.csdn.net/xd15010130025/article/details/77803332 版权声明:本文为博主原创文章,转载请附上博文链接!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值