1. 程式人生 > >ButtonGroup & JRadioButton(單選框)

ButtonGroup & JRadioButton(單選框)

關於ButtonGroup和JRadioButton的應用

import java.awt.*;

import javax.swing.*;

public class JRadioButtonTest extends ButtonGroup{
	
	JRadioButtonTest(){
		JFrame f = new JFrame("單選框示例");//建立一個JFrame的物件
		Container contenPane = f.getContentPane();//建立一個內容面板容器
		contenPane.setLayout(new FlowLayout());//設定該容器的佈局
		JPanel pl = new JPanel();//建立一個面板物件pl
		pl.setLayout(new GridLayout(1 ,3));//設定該面板的佈局管理器格式
		pl.setBorder(BorderFactory.createTitledBorder("選擇你喜歡的城市"));
		//定義3個JRadioButton單選按鈕
		JRadioButton r1 = new JRadioButton("北京");
		JRadioButton r2 = new JRadioButton("上海");
		JRadioButton r3 = new JRadioButton("青島");
		ButtonGroup bg = new ButtonGroup();//建立一個ButtonGroup物件
		bg.add(r1);
		bg.add(r2);
		bg.add(r3);
		pl.add(r1);
		pl.add(r2);
		pl.add(r3);
		contenPane.add(pl);
		f.pack();
		f.setVisible(true);
	}
	public static void main(String[] args){
		JRadioButtonTest jbt = new JRadioButtonTest();
	}
}


相關推薦

ButtonGroup & JRadioButton

關於ButtonGroup和JRadioButton的應用 import java.awt.*; import javax.swing.*; public class JRadioButtonT

d3之元件的運用,下拉列表,滑動軸,多

目錄 目錄 單選框 下拉列表 滑動軸 多選框 單選框 1.前端 <form name="myForm" action="" method="" style="posit

MUI-checkbox,左右位置+禁用設定

本文主要介紹checkbox(複選框)顯示的位置和禁用設定。 1、checkbox常用於多選的情況,比如批量刪除、新增群聊等, 結構如下: <div class="mui-input-row mui-checkbox"> <label>checkbox示例

jquery如何判斷checkbox是否被選中

經常碰到問題是關於checkbox的,這類問題主要就是前端獲取到一組複選框中被選中的複選框的值,所以使用jquery能很快的得到結果,下面是關於複選框的各種情況的解決辦法。 程式碼如下: <html> <head> <

POI 多下拉選單 匯出Excel模板 下拉單單,下拉選單多

最近公司要做Excel的模板匯出,匯入資料的工作,匯出時還要動態生成模板,並且生成單選下拉選單,和多選下拉選單。開始搞這個很快除了多選的都搞定了,就是多選卡住了。弄了很久。。。最後終於在和多方面的交流下成功弄出。之前在網上找不到方法很是頭疼,現在弄出來分享一下給大家。。歡迎指

Vuejs 的表type = "checkbox" type = "radio"

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, i

Winform/C#入門程式設計之第二部分常用控制元件五:控制元件RadioButton

簡介:         介紹單選框控制元件RadioButton。當多個 RadioButton 控制元件出現時,使使用者能夠從一組選項中選擇一個選項。   介紹: 1.屬性 常用屬性

Struts2中的ognl標籤介紹property標籤、iterator標籤、if/elseif/else標籤、url標籤、url標籤、radio、select下拉選擇

Struts2中的ognl標籤介紹(property標籤、iterator標籤、if/elseif/else標籤、url標籤、url標籤、radio單選框、select下拉選擇框) property標籤用於輸出指定值: <s:set name="name" value="'kk'" /> &l

使用css美化radio和複checkbox的樣式

//html <label> <input name="checkbox" class="checkbox" type="checkbox"/> <s>

UGUI學習筆記 ToggleGroup製作選擇題

      UGUI有一個Toggle元件 用來製作一個可勾選的選項,元件面板如下圖所示       其中Interactable選項用來選擇是否可操作,不勾選的話就是不可操作的,isOn是用來判斷當前這個Toggle的勾選狀態,OnValueChanged是當前Togg

js移除inputradio選中效果

上午做類似於這樣一個單選框效果,需要把彈窗內單選框後的文字賦值到彈窗父頁面。 可是在js中移除最開始是這麼做的。 $('.chose-box-li').children('input').attr('checked', 'true') $(this).children

WPF教程十九

單選框用於給使用者提供一個選項表,但是隻能選擇其中的一項。用複選框也可以實現這樣的功能,但是單選框更好的展示了他們能做的選擇。<span style="font-size:14px;"><Window x:Class="WpfTutorialSamples

HTML5:Animate cc互動功能之製作開關

1.需要實現的效果 2.步驟: a.實現點選功能 S.xld_btn1.txt.text="";//先將單選框的文字清空 //S.xld_btn1.txt.text是舞臺上的"xld_btn1影片剪輯",txt是指文字,text指文字內容 if(!S.xld

radio總結獲取值、設定預設選中值、樣式

input[type="radio"] + label::before {    content: "\a0";    display: inline-block;    vertical-align: middle;    width: 15px;    height: 15px;    margin-ri

安卓---RedioButton(按鈕)、CheckBox按鈕

radio eight color ont parent androi android 安卓 radi <RadioGroup android:layout_width="fill_parent" android:layout_height="wra

select標籤下拉多

預設顯示的文字變為不可選 <select> <option value="" disabled selected hidden>choose</option> <option value="0">0</option&g

C#點多次button僅生成一個窗體例模式

優化基本的單例模式 Form1 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; us

新增事件 JRadioButton

 //RaidoButton.java//為單選框新增事件//2009-11-18//<applet code=RadioButton width=200 height=100>//</applet> import javax.swing.*;impo

Tree樹設定單擊選中與取消多設定樹節點隱藏

前臺: 1. var deptTree = null; deptTree = $('#listDept'); //初始化樹 function initTree() { deptTree.tree({ url: '../dutyController/listDept

iOS tableView編輯刪除

viewDidload 新增for (int i = 0; i <_reouseArray.count ; i++) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [dict