1 JButton 囄和文字按钮的实现
| |
| JButton btn1 = new JButton("打开", new ImageIcon(ImageView.class.getResource("10.png"))) ; btn1.setHorizontalTextPosition(SwingConstants.CENTER); btn1.setVerticalTextPosition(SwingConstants.BOTTOM); |
效果?Q?/p>
2 JButton 囄透明按钮的实?/strong>
| |
| setLayout(new FlowLayout(FlowLayout.RIGHT, 30, 0)); btn1.setIcon(UIConfig.getImgUrl("常用交易?png")); btn1.setRolloverIcon(UIConfig.getImgUrl("常用交易.png")); btn1.setBorderPainted(false); btn1.setFocusPainted(false); btn1.setContentAreaFilled(false); btn1.setFocusable(true); btn1.setMargin(new Insets(0, 0, 0, 0)); btn1.setText("常用交易"); |
3JRadioButton 囄透明按钮的实?/strong>
JRadioButton radio = new JRadioButton(UIConfig.getImgUrl("常用交易?png") );
radio.setContentAreaFilled(false);
radio.setRolloverIcon(UIConfig.getImgUrl("常用交易.png"));
radio.setSelectedIcon(UIConfig.getImgUrl("常用交易.png"));
现提供两U方法:(x)
Ҏ(gu)一Q?nbsp;
如果你用qToolkit(java.awt.Toolkit)c,q将是一件很单的事情Q?nbsp;
Toolkit tk=Toolkit.getDefaultToolkit()
Image image=tk.createImage("image.gif"); /*image.gif是你的图?/
this.setIconImage(image);
注意Q这个图标一定要是好用的图标?br />
p么简单,看看Q已l变成你自己的图标了。Toolkit是个很有用类的,提供很多对窗口默认行为的修改Q下面随便提一下,怎么把默认的鼠标图标Ҏ(gu)你自q图标Q?nbsp;
Toolkit tk=Toolkit.getDefaultToolkit();
Image img=tk.getImage("mouse.gif"); /*mouse.gif是你的图?/
Cursor cu=tk.createCustomCursor(img,new Point(10,10),"stick");
this.setCursor(cu);
Ҏ(gu)二:(x)
用到ImageIconcdsetIconImageҎ(gu)?nbsp;
import javax.swing.*;
public class A extends JFrame {
String image = new String("face.gif"); //建立一个字W串保存要用的图标的路径Q关于java的\径请参考其它文?nbsp;
ImageIcon test = new ImageIcon(image); //建立一个ImageIconc,产生setIconImage()Ҏ(gu)需要的Image数据
public A() {
super("演示自定义标题栏的图标的Ҏ(gu)");
this.setIconImage(test.getImage()); //讄标题栏的图标为face.gif
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.show();
//this.setTitle("sdfsdf");
this.setSize(400,200);
}
public static void main(String[] args) {
A jIcon = new A();
}
}
此法本h再次化ؓ(f)两条语句Q?nbsp;
import javax.swing.*;
public class A extends JFrame {
ImageIcon test = new ImageIcon(new String(face.gif));//W一?nbsp;
public A() {
super("演示自定义标题栏的图标的Ҏ(gu)");
this.setIconImage(test.getImage()); //W二?nbsp;
this.setSize(400,200);
this.show();
}
public static void main(String[] args) {
A jIcon = new A();
}
}
下文转蝲自:(x)
Java'中的几种Look and Feel
1、Metal风格 (默认)
String lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
2、Windows风格
String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
3、Windows Classic风格
String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
4、Motif风格
String lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
5、Mac风格 (需要在相关的操作系l上方可实现)
String lookAndFeel = "com.sun.java.swing.plaf.mac.MacLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
6、GTK风格 (需要在相关的操作系l上方可实现)
String lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
7、可跨^台的默认风格
String lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
8、当前系l的风格
String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
在Java中让用户能够动态地更改应用的外观,可以l用h好地体验Q具体的实现方式是:(x)
1Q先使用UIManager.setLookAndFeel(String s)Ҏ(gu)讑֮对应的外?
2Q再使用SwingUtilities.updateComponentTreeUI(Component c)Ҏ(gu)立刻更新应用的外?br />q两个类均在javax.swing包中
c#键盘钩子Q?
public class Win32Hook
{
[DllImport("kernel32")]
public static extern int GetCurrentThreadId();
[DllImport("user32",CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(HookType idHook, HOOKPROC lpfn, int hmod, int dwThreadId);
[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int CallNextHookEx(int hhk,int nCode,int wParam,int lParam);
[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern bool UnHookWindowsHookEx(int hhk);
public enum HookType
{
WH_KEYBOARD = 2
}
public delegate int HOOKPROC(int nCode, int wParam, int lParam);
public int hhk;
public void SetHook()
{
// set the keyboard hook
hhk = SetWindowsHookEx(HookType.WH_KEYBOARD, new HOOKPROC(this.MyKeyboardProc), 0, GetCurrentThreadId());
}
public int MyKeyboardProc(int nCode, int wParam, int lParam)
{
//在这里放|你的处理代?br /> int iresult = 0;
if (nCode<=0)
{
iresult = CallNextHookEx(hhk, nCode, wParam, lParam);
return iresult;
}
if ((wParam >= 48 && wParam<=57)||(wParam >= 65 && wParam<=90)||(wParam >= 97 && wParam<=122))
{
Form1.rrrr += Convert.ToChar(wParam);
return 0;
}
return 0;
}
public bool UnHook()
{
return UnHookWindowsHookEx(hhk);
}
}
使用Q?
Win32Hook hook = new Win32Hook();
hook.SetHook();
this.richTextBox2.Text = rrrr;
hook.UnHook();
参考:(x)http://baike.baidu.com/view/1208620.htm
使用参照Q?a rel="nofollow" >http://www.codeproject.com/KB/system/globalsystemhook.aspx
(adamhtmei)
jQuery获取Select选择的Text和Value:
语法解释Q?br />1. $("#select_id").change(function(){//code...}); //为Selectd事gQ当选择其中一Ҏ(gu)触发
2. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text
3. var checkValue=$("#select_id").val(); //获取Select选择的Value
4. var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的烦引?br />5. var maxIndex=$("#select_id option:last").attr("index"); //获取Select最大的索引?br />jQuery讄Select选择?nbsp;Text和Value:
语法解释Q?br />1. $("#select_id ").get(0).selectedIndex=1; //讄Select索引gؓ(f)1的项选中
2. $("#select_id ").val(4); // 讄Select的Valuegؓ(f)4的项选中
3. $("#select_id option[text='jQuery']").attr("selected", true); //讄Select的Textgؓ(f)jQuery的项选中
jQueryd/删除Select的Option:(x)
语法解释Q?br />1. $("#select_id").append("<option value='Value'>Text</option>"); //为Selectq加一个Option(下拉?
2. $("#select_id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(W一个位|?
3. $("#select_id option:last").remove(); //删除Select中烦引值最大Option(最后一?
4. $("#select_id option[index='0']").remove(); //删除Select中烦引gؓ(f)0的Option(W一?
5. $("#select_id option[value='3']").remove(); //删除Select中Value='3'的Option
5. $("#select_id option[text='4']").remove(); //删除Select中Text='4'的Option
http://www.cnblogs.com/SAL2928/archive/2008/10/28/1321285.html
jquery radio取|checkbox取|select取|radio选中Qcheckbox选中Qselect选中Q及(qing)其相?nbsp;
?nbsp; 取一lradio被选中的?nbsp;
var item = $('input[name=items][checked]').val();
?nbsp; 取select被选中的文本
var item = $("select[name=items] option[selected]").text();
select下拉框的W二个元素ؓ(f)当前选中?nbsp;
$('#select_id')[0].selectedIndex = 1;
radio单选组的第二个元素为当前选中?nbsp;
$('input[name=items]').get(1).checked = true;
获取|(x)
文本框,文本区域Q?("#txt").attr("value")Q?nbsp;
多选框 checkboxQ?("#checkbox_id").attr("value")Q?nbsp;
单选组radioQ?nbsp; $("input[type=radio][checked]").val();
下拉框selectQ?nbsp;$('#sel').val();
控制表单元素Q?nbsp;
文本框,文本区域Q?("#txt").attr("value",'');//清空内容
$("#txt").attr("value",'11');//填充内容
多选框checkboxQ?nbsp; $("#chk1").attr("checked",'');//不打?nbsp;
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
单选组 radioQ?nbsp; $("input[type=radio]").attr("checked",'2');//讄value=2的项目ؓ(f)当前选中?nbsp;
下拉?nbsp; selectQ?nbsp; $("#sel").attr("value",'-sel3');//讄value=-sel3的项目ؓ(f)当前选中?nbsp;
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//d下拉框的option
$("#sel").empty()Q?/清空下拉?nbsp;
----------------------------------------------------------------------------------------------------
//遍历option和添加、移除option
function changeShipMethod(shipping){
var len = $("select[name=ISHIPTYPE] option").length
if(shipping.value != "CA"){
$("select[name=ISHIPTYPE] option").each(function(){
if($(this).val() == 111){
$(this).remove();
}
});
}else{
$("<option value='111'>UPS Ground</option>").appendTo($("select[name=ISHIPTYPE]"));
}
}
//取得下拉選單的選取?nbsp;
$(#testSelect option:selected').text();
?("#testSelect").find('option:selected').text();
?("#testSelect").val();
//////////////////////////////////////////////////////////////////
?nbsp; 性不好的可以收藏下:(x)
1,下拉?
var cc1 = $(".formc select[name='country'] option[selected]").text(); //得到下拉菜单的选中的文本(注意中间有空?
var cc2 = $('.formc select[name="country"]').val(); //得到下拉菜单的选中的?br />var cc3 = $('.formc select[name="country"]').attr("id"); //得到下拉菜单的选中的ID属性?br />$("#select").empty();//清空下拉?nbsp; //$("#select").html('');
$("<option value='1'>1111</option>").appendTo("#select")//d下拉框的option
E微解释一?
1.select[name='country'] option[selected] 表示hname 属性,
q?nbsp;且该属性gؓ(f)'country' 的select元素 里面的具有selected 属性的option 元素Q?nbsp;
2,单选框:
$("input[@type=radio][@checked]").val(); //得到单选框?nbsp; 选中的?注意中间没有I格)
$("input[@type=radio][@value=2]").attr("checked",'checked'); //讄单选框value=2的ؓ(f)选中状?(注意中间没有I格)
3,复选框:
$("input[@type=checkbox][@checked]").val(); //得到复选框的选中的第一的?br />$("input[@type=checkbox][@checked]").each(function() { //׃复选框一般选中的是多个,所以可以@环输?br />alert($(this).val());
});
$("#chk1").attr("checked",'');//不打?br />$("#chk2").attr("checked",true);// 打勾
if($("#chk1").attr('checked')==undefined){} //判断是否已经打勾
当然jquery的选择器是强大? q有很多Ҏ(gu).
<script src="jquery-1.2.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#selectTest").change(function()
{
//alert("Hello");
//alert($("#selectTest").attr("name"));
//$("a").attr("href","xx.html");
//window.location.href="xx.html";
//alert($("#selectTest").val());
alert($("#selectTest option[@selected]").text());
$("#selectTest").attr("value", "2");
});
});
</script>
<a href="#">aaass</a>
<!--下拉?->
<select id="selectTest" name="selectTest">
<option value="1">11</option>
<option value="2">22</option>
<option value="3">33</option>
<option value="4">44</option>
<option value="5">55</option>
<option value="6">66</option>
</select>
jquery radio取|checkbox取|select取|radio选中Qcheckbox选中Qselect选中Q及(qing)其相兌取一lradio被选中 的?br />var item = $('input[@name=items][@checked]').val();
获取select被?nbsp; 中项的文?br />var item = $("select[@name=items] option[@selected]").text();
select 下拉框的W二个元素ؓ(f)当前选中?br />$('#select_id')[0].selectedIndex = 1;
radio单选组的第二个 元素为当前选中?br />$('input[@name=items]').get(1).checked = true;
获取|(x)
文本 框,文本区域Q?("#txt").attr("value")Q?br />多选框 checkboxQ?("#checkbox_id").attr("value")Q?br />单选组radioQ?nbsp; $("input[@type=radio][@checked]").val();
下拉框selectQ?nbsp;$('#sel').val();
?nbsp; 制表单元素:(x)
文本框,文本区域Q?("#txt").attr("value",'');//清空内容
$("#txt").attr("value",'11');// 填充内容
多选框checkboxQ?nbsp; $("#chk1").attr("checked",'');//不打?br />$("#chk2").attr("checked",true);// 打勾
if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
单选组radioQ?nbsp; $("input[@type=radio]").attr("checked",'2');//讄value=2的项目ؓ(f)当前选中?br />下拉?nbsp;selectQ?nbsp; $("#sel").attr("value",'-sel3');//讄value=-sel3的项目ؓ(f)当前选中?br />$("<optionvalue='1'& gt;1111</option><optionvalue='2'>2222</option& gt;").appendTo("#sel")//d下拉框的option
$("#sel").empty()Q?/ 清空下拉?nbsp;
获取一lradio被选中的?br />var item = $('input[@name=items][@checked]').val();
获取select被选中的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的W二个元素ؓ(f)?nbsp; 前选中?br />$('#select_id')[0].selectedIndex = 1;
radio单选组的第二个元素为当前选中?br />$('input[@name=items]').get(1).checked = true;
获取|(x)
文本框,文本区域Q?("#txt").attr("value")Q?br />多选框 checkboxQ?("#checkbox_id").attr("value")Q?br />单选组radioQ?nbsp; $("input[@type=radio][@checked]").val();
下拉框selectQ?nbsp;$('#sel').val();
?nbsp; 制表单元素:(x)
文本框,文本区域Q?("#txt").attr("value",'');//清空内容
$("#txt").attr("value",'11');// 填充内容
多选框checkboxQ?nbsp; $("#chk1").attr("checked",'');//不打?br />$("#chk2").attr("checked",true);// 打勾
if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
单选组radioQ?nbsp; $("input[@type=radio]").attr("checked",'2');//讄value=2的项目ؓ(f)当前选中?br />下拉?nbsp;selectQ?nbsp; $("#sel").attr("value",'-sel3');//讄value=-sel3的项目ؓ(f)当前选中?br />$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//d下拉框的option
$("#sel").empty()Q?/ 清空下拉?
& ?& | & | ?/p> | |||
< ?< | <
| 于?/p> | |||
> ?> | >
| 大于?/p> | |||
" | " | 双引?/p> |
| ||
|
| I格 | |||
© | © | 版权W?/p> | |||
® | ®
| 注册W?/p> | |||
前者ؓ(f)字符转义序列Q后者ؓ(f)数字转义序列。数字{为字W对应的ASCII码倹{例如 & lt; font >昄为,<font>Q若直接写ؓ(f)则被认ؓ(f)是一个链接签?/p>