Java 组件显示在鼠标悬停时
我已经创建了一个swings应用程序,我正在尝试做的是,在单击按钮时向它添加一些组件。我能够做到这一点,但问题是,这些组件只有在我将鼠标悬停在它们上面时才会出现。我应该如何使它们在单击按钮后立即显示Java 组件显示在鼠标悬停时,java,swing,jbutton,Java,Swing,Jbutton,我已经创建了一个swings应用程序,我正在尝试做的是,在单击按钮时向它添加一些组件。我能够做到这一点,但问题是,这些组件只有在我将鼠标悬停在它们上面时才会出现。我应该如何使它们在单击按钮后立即显示 public TransferFrom() { count=1; setTitle("Transfer Form"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 924, 5
public TransferFrom() {
count=1;
setTitle("Transfer Form");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 924, 571);
pane = new JPanel();
pane.setBorder(new EmptyBorder(5, 5, 5, 5));
pane.setBackground(Color.decode("#5388BE"));
setContentPane(pane);
pane.setLayout(null);
trans_pln_name= new JTextField[30];
trans_pln_num= new JTextField[30];
trans_amt= new JTextField[30];
trans_inv_name= new JTextField[30];
trans_clr=new JButton[30];
trans_add=new JButton[30];
JLabel lblNewLabel = new JLabel("Transfer Form Page");
lblNewLabel.setForeground(new Color(240, 248, 255));
lblNewLabel.setBackground(Color.decode("#2c3e50"));
lblNewLabel.setBounds(0, 0, 1000, 40);
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 20));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
pane.add(lblNewLabel);
JLabel lbl1 = new JLabel("Action");
lbl1.setBounds(300, 95, 150, 30);
pane.add(lbl1);
JLabel lbl2 = new JLabel("Begin Date");
lbl2.setBounds(300, 139, 150, 30);
pane.add(lbl2);
JLabel lbl3 = new JLabel("Frequency");
lbl3.setBounds(300, 183, 150, 30);
pane.add(lbl3);
JLabel lbl4 = new JLabel("$ or %");
lbl4.setBounds(300, 227, 150, 30);
pane.add(lbl4);
JLabel lbl5 = new JLabel("Future Transaction Day");
lbl5.setBounds(300, 272, 150, 30);
pane.add(lbl5);
String[] action = { "Custom Transfer","Simple Transfer"};
trans_comboBox_3 = new JComboBox(action);
trans_comboBox_3.setSelectedIndex(0);
trans_comboBox_3.setBounds(470, 95, 180, 33);
pane.add(trans_comboBox_3);
String[] freq = {"Once", "Monthly","Quarterly","Semi-Annually","Annually"};
String[] dollar = { "Dollar", "Percent"};
trans_comboBox_4 = new JComboBox(freq);
trans_comboBox_4.setSelectedIndex(0);
trans_comboBox_4.setBounds(470, 183, 180, 33);
pane.add(trans_comboBox_4);
trans_comboBox_1 = new JComboBox(dollar);
trans_comboBox_1.setSelectedIndex(1);
trans_comboBox_1.setBounds(470, 227, 180, 33);
pane.add(trans_comboBox_1);
trans_comboBox_2 = new JComboBox();
for(int i=1;i<29;i++)
{
trans_comboBox_2.addItem(String.valueOf(i));
}
trans_comboBox_2.setSelectedIndex(0);
trans_comboBox_2.setBounds(470, 272, 180, 33);
pane.add(trans_comboBox_2);
JLabel lblMaritalStatus = new JLabel("On Future Date");
lblMaritalStatus.setBounds(300, 315, 150, 30);
pane.add(lblMaritalStatus);
trans_begin = new JTextField();
trans_begin.setColumns(10);
trans_begin.setBounds(470, 139, 180, 33);
pane.add(trans_begin);
trans_future = new JTextField();
trans_future.setColumns(10);
trans_future.setBounds(470, 320, 180, 33);
pane.add(trans_future);
addItem();
pane.revalidate();
JButton btnNewButton = new JButton("Create Test Case");
btnNewButton.setBounds(470, 800, 180, 33);
btnNewButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
/*assignXML();
System.out.println(XML);
XMLPath=new String[10];
XMLPath[0]="C:\\Users\\paranja\\Desktop\\UI\\"+main_test_num.getText()+".xml";
File fileName = new File(XMLPath[0] );
if(fileName.exists())
{
actionDialog = JOptionPane.showConfirmDialog(getContentPane(),
"Replace existing file?");
if (actionDialog == JOptionPane.NO_OPTION)
return;
}
try
{
BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
out.write(XML);
out.close();
}
catch(Exception ex)
{
System.err.println("Error: " + ex.getMessage());
}
CreateGroovyAndUploadXML create=new CreateGroovyAndUploadXML();
create.CreateGroovy(XMLPath);
*/}
});
pane.add(btnNewButton);
}
private void addItem() {
// TODO Auto-generated method stub
pane.revalidate();
trans_pln_num[count]=new JTextField();
trans_pln_num[count].setBounds(50, (300+count*100), 100, 50);
trans_pln_num[count].setColumns(10);
trans_pln_num[count].setBorder(
BorderFactory.createTitledBorder("Plan Number"));
pane.add(trans_pln_num[count]);
trans_pln_name[count]=new JTextField();
trans_pln_name[count].setBounds(200, (300+count*100), 100, 50);
trans_pln_name[count].setColumns(10);
trans_pln_name[count].setBorder(
BorderFactory.createTitledBorder("Plan Name"));
pane.add(trans_pln_name[count]);
trans_inv_name[count]=new JTextField();
trans_inv_name[count].setBounds(350, (300+count*100), 200, 50);
trans_inv_name[count].setColumns(10);
trans_inv_name[count].setBorder(
BorderFactory.createTitledBorder("Investment Name"));
pane.add(trans_inv_name[count]);
trans_amt[count]=new JTextField();
trans_amt[count].setBounds(600, (300+count*100), 200, 50);
trans_amt[count].setColumns(10);
trans_amt[count].setBorder(
BorderFactory.createTitledBorder("Amount"));
pane.add(trans_amt[count]);
trans_clr[count]=new JButton("Clear");
trans_clr[count].setBounds(850, (300+count*100), 50, 50);
pane.add(trans_clr[count]);
trans_add[count]=new JButton("+");
trans_add[count].setBounds(950, (300+count*100), 50, 50);
trans_add[count].addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
count=count+1;
addItem();
}
});
pane.add(trans_add[count]);
pane.revalidate();
}
public TransferFrom(){
计数=1;
转让书(“转让书”);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
立根(100100924571);
pane=newjpanel();
窗格.新订单(新的空订单(5,5,5,5));
窗格背景(彩色解码(#5388BE));
设置内容窗格(窗格);
pane.setLayout(空);
trans_pln_name=新的JTextField[30];
trans_pln_num=新的JTextField[30];
trans_amt=新的JTextField[30];
trans_inv_name=new JTextField[30];
trans_clr=新的JButton[30];
trans_add=新的JButton[30];
JLabel lblNewLabel=新JLabel(“转账表单页面”);
lblNewLabel.setForeground(新颜色(240248255));
lblNewLabel.setBackground(彩色解码(“#2c3e50”);
lblNewLabel.setBounds(0,0,1000,40);
lblNewLabel.setFont(新字体(“Tahoma”,Font.BOLD,20));
lblNewLabel.SETHORISTALLING(旋转约束中心);
添加窗格(lblNewLabel);
JLabel lbl1=新JLabel(“动作”);
lbl1.立根(300,95,150,30);
窗格。添加(lbl1);
JLabel lbl2=新JLabel(“开始日期”);
lbl2.立根(300、139、150、30);
窗格。添加(lbl2);
JLabel lbl3=新JLabel(“频率”);
lbl3.立根(30018315030);
窗格。添加(lbl3);
JLabel lbl4=新的JLabel(“$或%”);
lbl4.立根(300227150,30);
窗格。添加(lbl4);
JLabel lbl5=新JLabel(“未来交易日”);
lbl5.立根(300272150,30);
窗格。添加(lbl5);
String[]action={“自定义传输”,“简单传输”};
trans_comboBox_3=新JComboBox(操作);
trans_组合框_3.设置所选索引(0);
trans_组合框_3.立根(470,95,180,33);
添加(trans_组合框_3);
字符串[]freq={“一次”、“每月”、“季度”、“半年”、“每年”};
字符串[]美元={“美元”,“百分比”};
trans_comboBox_4=新的JComboBox(频率);
trans_组合框_4.设置所选索引(0);
trans_组合框_4.立根(470、183、180、33);
添加(trans_组合框_4);
trans_comboBox_1=新的JComboBox(美元);
trans_组合框_1.设置所选索引(1);
trans_组合框_1.立根(470、227、180、33);
添加(trans_组合框_1);
trans_comboBox_2=新的JComboBox();
对于(int i=1;irevalidate
对您毫无用处,因为您决定不使用布局管理器。revalidate
只需更新容器及其子容器的所有布局信息。尝试改用repaint
和布局管理器,以便更快发布SSCCE/MCVE、简短、可运行、可编译的代码r使用JTable
instead@MadProgrammer我对Swigs还很陌生。目前,我还没有使用布局管理器。但repaint命令实际上很有帮助!谢谢!现在是开始使用布局管理器的时候了-