对于想了解JButton.setBounds的读者,本文将提供新的信息,我们将详细介绍x,y,w,h似乎不起作用,并且为您提供关于(15)各种Button与排列OutlineButton,Button
对于想了解JButton.setBounds的读者,本文将提供新的信息,我们将详细介绍x,y,w,h似乎不起作用,并且为您提供关于(15)各种Button 与排列 OutlineButton,ButtonBar,Expanded,RaisedButton,StadiumBorder,FlatButton.icon、@Column(unique = true)似乎不起作用、@WithUserDetails似乎不起作用、Android ShowCaseView的buttonLayoutParams不起作用的有价值信息。
本文目录一览:- JButton.setBounds(x,y,w,h)似乎不起作用
- (15)各种Button 与排列 OutlineButton,ButtonBar,Expanded,RaisedButton,StadiumBorder,FlatButton.icon
- @Column(unique = true)似乎不起作用
- @WithUserDetails似乎不起作用
- Android ShowCaseView的buttonLayoutParams不起作用
JButton.setBounds(x,y,w,h)似乎不起作用
import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.SwingUtilities;public class SimpleExample extends JFrame { public SimpleExample() { setTitle("Simple example"); setSize(500, 500); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); JButton jb = new JButton("TEST"); jb.setBorderPainted(true); jb.setBounds(5, 5, 1, 1); ---> This line add(jb); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { SimpleExample ex = new SimpleExample(); ex.setVisible(true); } }); }}
只需创建一个首选大小的简单按钮即可。该setBounds
方法似乎不起作用。我要去哪里错了?
答案1
小编典典您的框架受布局管理器的控制,它正在决定如何最好地布局组件,并覆盖您使用所指定的值 setBounds
现代GUI需要在各种不同的图形环境中运行(甚至在同一OS上),例如,包括不同的DPI,屏幕大小和字体设置。
布局管理器使您不必担心(减少)这些问题,强烈建议您使用它们
看一眼
- 使用布局管理器
- 布局管理器的可视指南
更多细节
(15)各种Button 与排列 OutlineButton,ButtonBar,Expanded,RaisedButton,StadiumBorder,FlatButton.icon
效果
至于倒数第二行和倒数第一行的效果为啥一样。。可能是fluttersdk升级了。。之前的api不再生效。。算是留坑!
代码
import ''package:flutter/material.dart'';
class ButtonDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Widget _floatButtonDemo =
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
FlatButton(
onPressed: () {},
child: Text("FlatButton"),
splashColor: Colors.grey,
textColor: Theme.of(context).accentColor,
color: Colors.black87,
),
FlatButton.icon(
icon: Icon(Icons.add),
onPressed: () {},
label: Text("FlatButton.icon"),
splashColor: Colors.grey,
textColor: Theme.of(context).accentColor,
color: Colors.black87,
)
]);
final Widget _raisedButtonDemo =
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Theme(
// data: ThemeData(),
data: Theme.of(context).copyWith(
buttonColor: Theme.of(context).accentColor,
buttonTheme: ButtonThemeData(
textTheme: ButtonTextTheme.primary,
// shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
shape: StadiumBorder(),
)),
child: RaisedButton(
onPressed: () {},
child: Text("RaisedButton"),
splashColor: Colors.grey,
textColor: Theme.of(context).accentColor,
// color: Colors.white,
// textTheme: ButtonTextTheme.primary,
elevation: 0.0,
)),
SizedBox(
width: 16.0,
),
RaisedButton.icon(
icon: Icon(Icons.add),
onPressed: () {},
label: Text("RaisedButton.icon"),
splashColor: Colors.grey,
textColor: Theme.of(context).accentColor,
elevation: 12.0,
)
]);
final Widget _outerLineButtonDemo =
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Theme(
// data: ThemeData(),
data: Theme.of(context).copyWith(
buttonColor: Theme.of(context).accentColor,
buttonTheme: ButtonThemeData(
textTheme: ButtonTextTheme.primary,
// shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
shape: StadiumBorder(),
)),
child: OutlineButton(
onPressed: () {},
child: Text("OutlineButton"),
splashColor: Colors.grey[100],
textColor: Colors.black,
borderSide: BorderSide(color: Colors.black),
highlightedBorderColor: Colors.grey,
// textTheme: ButtonTextTheme.primary,
)),
SizedBox(
width: 16.0,
),
OutlineButton.icon(
icon: Icon(Icons.add),
onPressed: () {},
label: Text("OutlineButton.icon"),
splashColor: Colors.grey,
textColor: Theme.of(context).accentColor,
)
]);
final Widget _widthOuterLineButton = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 200,
child: OutlineButton(
onPressed: () {},
child: Text("_widthOuterLineButton"),
splashColor: Colors.grey,
textColor: Colors.blue,
),
)
],
);
final Widget _expendOuterLineButton = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: OutlineButton(
onPressed: () {},
child: Text("_expendOuterLineButton"),
splashColor: Colors.grey,
textColor: Colors.blue,
),
)
],
);
final Widget _expend2OuterLineButton = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
flex: 1,
child: OutlineButton(
onPressed: () {},
child: Text("权重 for 1"),
splashColor: Colors.grey,
textColor: Colors.blue,
),
),
SizedBox(
width: 15,
),
Expanded(
//权重属性
flex: 2,
child: OutlineButton(
onPressed: () {},
child: Text("权重 for 2"),
splashColor: Colors.grey,
textColor: Colors.blue,
),
)
],
);
//一行并列行显示的按钮
final Widget _buttonBar = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ButtonBar(
children: [
OutlineButton(
onPressed: () {},
child: Text("ButtonBar"),
splashColor: Colors.grey,
textColor: Colors.blue,
),
OutlineButton(
onPressed: () {},
child: Text("ButtonBar"),
splashColor: Colors.grey,
textColor: Colors.blue,
),
],
)
],
);
//对刚才的并排中间添加边距
final Widget _buttonBarPaddingv = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Theme(
data: Theme.of(context).copyWith(
buttonTheme: ButtonThemeData(
padding: EdgeInsets.symmetric(horizontal: 100.0))),
child: ButtonBar(
children: [
OutlineButton(
onPressed: () {},
child: Text("ButtonBar"),
splashColor: Colors.grey,
textColor: Colors.blue,
),
OutlineButton(
onPressed: () {},
child: Text("ButtonBar"),
splashColor: Colors.grey,
textColor: Colors.blue,
),
],
),
)
],
);
return Scaffold(
appBar: AppBar(
title: Text("button Demo"),
elevation: 0.0,
),
body: Container(
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_floatButtonDemo,
_raisedButtonDemo,
_outerLineButtonDemo,
_widthOuterLineButton,
_expendOuterLineButton,
_expend2OuterLineButton,
_buttonBar,
_buttonBarPaddingv
],
),
),
);
}
}
@Column(unique = true)似乎不起作用
即使将属性设置为@Column(unique=true)
,我仍然会插入重复的条目。
@Entitypublic class Customer { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(unique=true ) private String name; ...}
我设置了name
使用定期EL
在JSF
。我没有用create
表JPA
答案1
小编典典我没有使用JPA创建表
然后,您应该在CREATE
语句中向表中添加唯一约束,例如,如果您使用的是MySQL:
create Customer (id int primary key, name varchar(255) unique);
@WithUserDetails似乎不起作用
如何解决@WithUserDetails似乎不起作用?
我目前无法测试,但这是一个 可能的 解决方案。
查看@WithUserDetails实现:
@WithSecurityContext(factory = WithUserDetailsSecurityContextFactory.class)
public @interface WithUserDetails {
...
}
final class WithUserDetailsSecurityContextFactory implements
WithSecurityContextFactory<WithUserDetails> {
private beanfactory beans;
@Autowired
public WithUserDetailsSecurityContextFactory(beanfactory beans) {
this.beans = beans;
}
public SecurityContext createSecurityContext(WithUserDetails withUser) {
String beanName = withUser.userDetailsServiceBeanName();
UserDetailsService userDetailsService = StringUtils.hasLength(beanName)
? this.beans.getBean(beanName, UserDetailsService.class)
: this.beans.getBean(UserDetailsService.class);
String username = withUser.value();
Assert.hasLength(username, "value() must be non empty String");
UserDetails principal = userDetailsService.loadUserByUsername(username);
Authentication authentication = new UsernamePasswordAuthenticationToken(
principal, principal.getpassword(), principal.getAuthorities());
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(authentication);
return context;
}
}
您可以按照相同的模式创建您选择的安全上下文:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@WithSecurityContext(factory = WithoutUserFactory.class)
public @interface WithoutUser {
}
public class WithoutUserFactory implements WithSecurityContextFactory<WithoutUser> {
public SecurityContext createSecurityContext(WithoutUser withoutUser) {
return SecurityContextHolder.createEmptyContext();
}
}
其他可获得的注释:WithAnonymousUser
,WithMockUser
,WithSecurityContext
(和WithUserDetails
)
解决方法
我有一个使用Spring Social Security进行身份验证和授权的应用程序。不幸的是,我在模拟Spring
Security时遇到了一些问题。似乎根本不起作用。
我有一个REST控制器,如果它应返回的实体的标识符不可用,则返回404 Not
Found。如果用户未登录,则任何页面都将重定向到我的应用程序的社交登录页面。
我在这里读到,@WithUserDetails
注释最适合我。
所以我的测试方法看起来像这样
@Test
@SqlGroup({
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD,statements = "INSERT INTO UserAccount(id,creationtime,modificationtime,version,email,firstname,lastname,role,signinprovider) VALUES (1,''2008-08-08 20:08:08'',1,''user'',''John'',''Doe'',''ROLE_USER'',''FACEBOOK'')"),})
@Rollback
@WithUserDetails
public void ifNoTeamsInTheDatabaseThenTheRestControllerShouldReturnNotFoundHttpStatus() {
ResponseEntity<String> response = restTemplate.getForEntity("/getTeamHistory/{team}",String.class,"Team");
Assert.assertEquals(HttpStatus.NOT_FOUND,response.getStatusCode());
}
但这似乎根本不起作用。看来测试方法是用匿名用户执行的,因为我得到的状态是200 OK。
我的测试课是这样注释的
@RunWith(SpringRunner.class)
@ActiveProfiles("dev")
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@Transactional
public class TeamRestControllerTest {
//...
}
有没有人遇到过由Spring Social提供的嘲笑Spring Security这样的问题?
Android ShowCaseView的buttonLayoutParams不起作用
我使用了这段代码(在库中也一样):
// The following code will reposition the OK button to the left. RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); lps.addRule(RelativeLayout.ALIGN_PARENT_BottOM); lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT); int margin = ((Number) (getResources().getdisplayMetrics().density * 12)) .intValue(); lps.setMargins(margin,margin,margin); View showcasedView = findViewById(R.id.ib_next); ViewTarget target = new ViewTarget(showcasedView); ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions(); co.buttonLayoutParams = lps; co.fadeInDuration = 1000; co.fadeOutDuration = 1000; ShowcaseView sv = ShowcaseView.insertShowcaseView(target,this,R.string.showcase_title,R.string.showcase_details,co);
但它不起作用?任何人都可以告诉问题在哪里?
解决方法
RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); // This aligns button to the bottom left side of screen lps.addRule(RelativeLayout.ALIGN_PARENT_BottOM); lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT); // Set margins to the button,we add 16dp margins here int margin = ((Number) (getResources().getdisplayMetrics().density * 16)).intValue(); lps.setMargins(margin,margin); ViewTarget target = new ViewTarget(R.id.buttonBlocked,this); sv = new ShowcaseView.Builder(this) .withMaterialShowcase() .setTarget(target) .setContentTitle(R.string.showcase_main_title) .setContentText(R.string.showcase_main_message) .build(); // Set declared button position to ShowcaseView sv.setButtonPosition(lps);
这对我有用,希望它对某人有所帮助.
今天关于JButton.setBounds和x,y,w,h似乎不起作用的分享就到这里,希望大家有所收获,若想了解更多关于(15)各种Button 与排列 OutlineButton,ButtonBar,Expanded,RaisedButton,StadiumBorder,FlatButton.icon、@Column(unique = true)似乎不起作用、@WithUserDetails似乎不起作用、Android ShowCaseView的buttonLayoutParams不起作用等相关知识,可以在本站进行查询。
本文标签: