设置超链接的按钮效果(向下按)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_35768238/article/details/79974949

      设置超链接像按钮一样,并且当鼠标移到一个超链接上是,会有向下按的凹陷效果。通常是利用a:hover,将链接向下、向右各移动一个像素即可。

<body>
    <a href="#">首页</a>
    <a href="#">团购</a>
    <a href="#">女装</a>
    <a href="#">男装</a>

  <style type="text/css">
      a{font-family:"幼圆";font-size:2em;text-align:center;margin:5px;color:#000}
      a:link,a:visited{color:#ac2300; text-decoration:none; padding:4px 10px; background-color:#ccd8db; border-top:1px solid #eeeeee;
    border-left:1px solid #eeeeee;border-bottom:1px solid #717171;border-right:1px solid #717171;}
      a:hover{color:#821818; text-decoration:underline;padding:5px 12px 5px 12px; background-color:#e2c4c9; border-top:1px solid #717171;
    border-left:1px solid #717171;border-bottom:1px solid #eeeeee;border-right:1px solid #eeeeee;}
  </style>
</body>

效果图如下:

 未点击状态

点击首页时的状态

展开阅读全文

为什么按钮按下去没有按下去的效果

06-24

下面是找到的一段JTable中添加JButton的 代码,为什么按钮按下去没什么效果?求大神指导![code=Java][/code]rnrnrnimport javax.swing.*;rnimport javax.swing.table.*;rnimport java.awt.*;rnimport java.awt.event.*;rnrnclass JTableButtonRenderer implements TableCellRenderer rn private TableCellRenderer __defaultRenderer;rnrn public JTableButtonRenderer(TableCellRenderer renderer) rn __defaultRenderer = renderer;rn rnrn public Component getTableCellRendererComponent(JTable table, Object value,rn boolean isSelected,rn boolean hasFocus,rn int row, int column)rn rn if(value instanceof Component)rn return (Component)value;rn return __defaultRenderer.getTableCellRendererComponent(rn table, value, isSelected, hasFocus, row, column);rn rnrnrnclass JTableButtonModel extends AbstractTableModel rn private Object[][] __rows = rn "One", new JButton("Button One") ,rn "Two", new JButton("Button Two") ,rn "Three", new JButton("Button Three") ,rn "Four", new JButton("Button Four") rn ;rnrn private String[] __columns = "Numbers", "Buttons" ;rnrn public String getColumnName(int column) rn return __columns[column];rn rnrn public int getRowCount() rn return __rows.length;rn rnrn public int getColumnCount() rn return __columns.length;rn rnrn public Object getValueAt(int row, int column) rn return __rows[row][column];rn rnrn public boolean isCellEditable(int row, int column) rn return false;rn rnrn public Class getColumnClass(int column) rn return getValueAt(0, column).getClass();rn rnrnrnclass JTableButtonMouseListener implements MouseListener rn private JTable __table;rnrn private void __forwardEventToButton(MouseEvent e) rn TableColumnModel columnModel = __table.getColumnModel();rn int column = columnModel.getColumnIndexAtX(e.getX());rn int row = e.getY() / __table.getRowHeight();rn Object value;rn JButton button;rn MouseEvent buttonEvent;rnrn if(row >= __table.getRowCount() || row < 0 ||rn column >= __table.getColumnCount() || column < 0)rn return;rnrn value = __table.getValueAt(row, column);rnrn if(!(value instanceof JButton))rn return;rnrn button = (JButton)value;rnrn// buttonEvent =rn// (MouseEvent)SwingUtilities.convertMouseEvent(__table, e, button);rn// button.dispatchEvent(buttonEvent);rn // This is necessary so that when a button is pressed and releasedrn // it gets rendered properly. Otherwise, the button may still appearrn // pressed down when it has been released.rn __table.repaint();rn rnrn public JTableButtonMouseListener(JTable table) rn __table = table;rn rnrn public void mouseClicked(MouseEvent e) rn __forwardEventToButton(e);rn rnrn public void mouseEntered(MouseEvent e) rn __forwardEventToButton(e);rn rnrn public void mouseExited(MouseEvent e) rn __forwardEventToButton(e);rn rnrn public void mousePressed(MouseEvent e) rn __forwardEventToButton(e);rn rnrn public void mouseReleased(MouseEvent e) rn __forwardEventToButton(e);rn rnrnrnpublic final class JTableButton extends JFrame rn private JTable __table;rn private JScrollPane __scrollPane;rnrn public JTableButton() rn super("JTableButton Demo");rn TableCellRenderer defaultRenderer;rnrn __table = new JTable(new JTableButtonModel());rn defaultRenderer = __table.getDefaultRenderer(JButton.class);rn __table.setDefaultRenderer(JButton.class,rn new JTableButtonRenderer(defaultRenderer));rn __table.setPreferredScrollableViewportSize(new Dimension(400, 200));rn __table.addMouseListener(new JTableButtonMouseListener(__table));rnrn __scrollPane = new JScrollPane(__table);rn setContentPane(__scrollPane);rn rnrn public static void main(String[] args) rn Frame frame;rn WindowListener exitListener;rnrn exitListener = new WindowAdapter() rn public void windowClosing(WindowEvent e) rn Window window = e.getWindow();rn window.setVisible(false);rn window.dispose();rn System.exit(0);rn rn ;rnrn frame = new JTableButton();rn frame.addWindowListener(exitListener);rn frame.pack();rn frame.setVisible(true);rn rnrn 论坛

没有更多推荐了,返回首页