小编use*_*343的帖子

如何将悬停效果放在jbutton上?

我正在尝试创建一个Java桌面应用程序,我使用两个按钮.我想在这些按钮中添加悬停效果.我想:当我点击任何按钮时,它应该改变它的背景颜色.

我怎样才能实现它?

这是我的代码:

public class Party1Party2 extends JFrame
{
    JButton b1;
    JButton b2;
    Container pane;

    public Party1Party2()
    {
        getContentPane().setBackground(new java.awt.Color(255, 255, 255));

    b2.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent ae)
        {
            JOptionPane.showMessageDialog(frame, "Welcome to allhabad High Court");
        }
    });

    b1.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent ae)
        {
            JOptionPane.showMessageDialog(frame, "Welcome to allhabad High Court");

        }
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

java swing rollover jbutton mouselistener

7
推荐指数
1
解决办法
5万
查看次数

如何在jlabel之间给空格?

嗨,我正在尝试制作 Java 桌面应用程序,其中我使用多个 jlabel 我想在每个标签之间留出很小的空间

我怎样才能做到这一点

这是我的代码

public class Second extends javax.swing.JFrame {
JLabel label=new JLabel();
    /**
     * Creates new form Second
     */
    public Second() {
          this.getContentPane().setBackground(new java.awt.Color(255, 140, 0));
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setUndecorated(true);
JButton print= new JButton();
print.setBackground(new java.awt.Color(153, 153, 0));
            print.setOpaque(true);
            print.setBounds(525,1282,130,85);
            print.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
          print.setForeground(new java.awt.Color(255,255,255));
            print.setText("Print");
            this.add(print);

          JButton home= new JButton();
home.setBackground(new java.awt.Color(153, 153, 0));
            home.setOpaque(true);
            home.setBounds(640,1282,130,85);
            home.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
          home.setForeground(new java.awt.Color(255, 255,255 ));
            home.setText("Home");
            this.add(home);

int Height …
Run Code Online (Sandbox Code Playgroud)

java swing jlabel layout-manager null-layout-manager

1
推荐指数
1
解决办法
1万
查看次数

如何使用正则表达式的数字?

我有一个字符串,其中包含数字和单词,我想在java中使用正则表达式.

String  s="S.No.DistrictMarketPrice 1 Agra Achhnera NIL 2 Agra Agra 1450 3 Agra Fatehabad NIL 4 Agra Fatehpur Sikri 8765 5 Agra Jagner NIL 6 Agra Jarar NIL 7 Agra Khairagarh NIL 8 Agra Shamshabad NIL 9 Aligarh Atrauli 1298 10 Aligarh Chharra NIL";
Run Code Online (Sandbox Code Playgroud)

我想打破这个字符串.我希望新行中的每个字符串都应该从精确的serino开始

我怎样才能得到这个输出

S.No  .District  Market                Price
1      Agra      Achhnera              NIL
2      Agra      Agra                 1450
3      Agra      Fatehabad             NIL
4      Agra      Fatehpur Sikri       8765 
Run Code Online (Sandbox Code Playgroud)

java regex

-1
推荐指数
1
解决办法
71
查看次数