- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望标签 Hotel Management System copyright 2016 出现在底部的 MatteBorder
下方,并且也居中。我已尝试 copyrightL.setVerticalAlignment(JLabel.BOTTOM);
但它似乎不起作用。
这是我的代码:
public class Admin_hs extends JFrame {
JButton bking_btn= new JButton("Bookings");
JButton fd_btn= new JButton("Financial Data");
JButton ctm_btn= new JButton("Customers");
JButton room_btn= new JButton("Rooms");
JButton adc_btn= new JButton("Additional Costs");
JButton endb_btn= new JButton("Ending Bookings");
//Images
JLabel bking_img= new JLabel();
JLabel fd_img= new JLabel();
JLabel ctm_img= new JLabel();
JLabel room_img= new JLabel();
JLabel adc_img= new JLabel();
JLabel endb_img= new JLabel();
JLabel copyrightL = new JLabel("Hotel Management System \u00a9 2016");
///Panels
JPanel pnl1= new JPanel();
JPanel pnl= new JPanel((new FlowLayout(FlowLayout.LEFT)));
///Constructors
public Admin_hs(){
this.setTitle("Welcome Admin!");
this.setLayout(new GridBagLayout());
///Setting a layout
pnl1.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth= GridBagConstraints.REMAINDER;
gbc.fill= gbc.HORIZONTAL;
gbc.weightx = 1; // ADD THIS LINE so it uses all the existing window size in x direction
pnl1.add(pnl); // ADD THIS LINE
pnl.setLayout(new GridBagLayout());
GridBagConstraints gc= new GridBagConstraints();
///First Column of Grid
gc.insets = new Insets(6, 6, 6, 6);
gc.anchor = GridBagConstraints.WEST;
gc.weightx = 0.5;
gc.weighty = 0.5;
gc.gridx = 0;
gc.gridy = 0;
pnl.add(bking_btn, gc);
gc.gridx = 0;
gc.gridy = 1;
pnl.add(fd_btn, gc);
gc.gridx = 0;
gc.gridy = 2;
pnl.add(ctm_btn, gc);
gc.gridx = 0;
gc.gridy = 3;
pnl.add(room_btn, gc);
gc.gridx = 0;
gc.gridy = 4;
pnl.add(adc_btn, gc);
gc.gridx = 0;
gc.gridy = 5;
pnl.add(endb_btn, gc);
gc.gridx = 0;
gc.gridy = 8;
pnl.add(copyrightL, gc);
/////second column of grid
gc.anchor = GridBagConstraints.WEST;
gc.gridx = 1;
gc.gridy = 0;
bking_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/booking.jpg"));
pnl.add(bking_img, gc);
gc.gridx = 1;
gc.gridy = 1;
fd_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/fd.jpg"));
pnl.add(fd_img, gc);
gc.gridx = 1;
gc.gridy = 2;
ctm_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/guest.jpg"));
pnl.add(ctm_img, gc);
gc.gridx = 1;
gc.gridy = 3;
room_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/room.jpg"));
pnl.add(room_img, gc);
gc.gridx = 1;
gc.gridy = 4;
adc_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/adc.jpg"));
pnl.add(adc_img, gc);
gc.gridx = 1;
gc.gridy = 5;
endb_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/endb.png"));
pnl.add(endb_img, gc);
//copyrightL.setHorizontalAlignment(JLabel.CENTER);
//copyrightL.setVerticalAlignment(JLabel.BOTTOM);
//pnl.add(copyrightL);
pnl1.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
this.add(pnl1,gbc);
}
}
主类
public class Admin_main {
public static void main(String[] args) {
Admin_hs adm= new Admin_hs();
adm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
adm.pack();
adm.setVisible(true);
adm.setSize(780,520);
}
}
目前的外观如下:
<小时/>编辑:
它以这种方式对我有用:
public class Admin_hs extends JFrame {
JButton bking_btn= new JButton("Bookings");
JButton fd_btn= new JButton("Financial Data");
JButton ctm_btn= new JButton("Customers");
JButton room_btn= new JButton("Rooms");
JButton adc_btn= new JButton("Additional Costs");
JButton endb_btn= new JButton("Ending Bookings");
//Images
JLabel bking_img= new JLabel();
JLabel fd_img= new JLabel();
JLabel ctm_img= new JLabel();
JLabel room_img= new JLabel();
JLabel adc_img= new JLabel();
JLabel endb_img= new JLabel();
JLabel copyrightL = new JLabel("Hotel Management System \u00a9 2016");
///Panels
JPanel pnl1= new JPanel();
JPanel pnl2= new JPanel(new GridBagLayout());
///Constructors
public Admin_hs(){
this.setTitle("Welcome Admin!");
this.setLayout(new GridBagLayout());
///Setting a layout
pnl1.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill= gbc.HORIZONTAL;
GridBagConstraints gc= new GridBagConstraints();
///First Column of Grid
gc.insets = new Insets(6, 6, 6, 6);
gc.anchor = GridBagConstraints.WEST;
gc.weightx = 0.5;
gc.weighty = 0.5;
gc.gridx = 0;
gc.gridy = 0;
pnl1.add(bking_btn, gc);
gc.gridx = 0;
gc.gridy = 1;
pnl1.add(fd_btn, gc);
gc.gridx = 0;
gc.gridy = 2;
pnl1.add(ctm_btn, gc);
gc.gridx = 0;
gc.gridy = 3;
pnl1.add(room_btn, gc);
gc.gridx = 0;
gc.gridy = 4;
pnl1.add(adc_btn, gc);
gc.gridx = 0;
gc.gridy = 5;
pnl1.add(endb_btn, gc);
gc.gridx = 0;
gc.gridy = 8;
pnl1.add(copyrightL, gc);
/////second column of grid
gc.anchor = GridBagConstraints.WEST;
gc.gridx = 1;
gc.gridy = 0;
bking_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/booking.jpg"));
pnl1.add(bking_img, gc);
gc.gridx = 1;
gc.gridy = 1;
fd_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/fd.jpg"));
pnl1.add(fd_img, gc);
gc.gridx = 1;
gc.gridy = 2;
ctm_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/guest.jpg"));
pnl1.add(ctm_img, gc);
gc.gridx = 1;
gc.gridy = 3;
room_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/room.jpg"));
pnl1.add(room_img, gc);
gc.gridx = 1;
gc.gridy = 4;
adc_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/adc.jpg"));
pnl1.add(adc_img, gc);
gc.gridx = 1;
gc.gridy = 5;
endb_img.setIcon(new ImageIcon("C:/Users/Diksha/Desktop/OOSD Assignment/icons/60-60/endb.png"));
pnl1.add(endb_img, gc);
pnl1.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
pnl2.add(copyrightL, gbc);
gbc.gridwidth = 1;
gbc.weightx = 1.0;
gbc.gridx = 0;
gbc.gridy = 0;
add(pnl1, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
add(pnl2, gbc);
}
}
这是现在的样子:
按钮不知何故移到了左边。这对我来说很好,因为出于某种原因我不得不将它们移到左边。我怎样才能得到他们对应的图像在左边呢?我的意思是,如何使图像更靠近左侧的按钮?
最佳答案
我相信最简单的方法是使用与此类似的代码
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame {
private JPanel testPanel = new JPanel(new GridBagLayout()), testPanel2 = new JPanel(new GridBagLayout());
private GridBagConstraints c = new GridBagConstraints();
private JLabel label1 = new JLabel("Something"), label2 = new JLabel("Something Else");
Test() {
super("Example Frame");
setLayout(new GridBagLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildGUI();
c.weightx = 1.0;
c.gridx = 0;
c.gridy = 0;
add(testPanel, c);
c.gridx = 0;
c.gridy = 1;
add(testPanel2, c);
pack();
setVisible(true);
}
private void buildGUI() {
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
testPanel.add(label1, c);
testPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
c.gridx = 0;
c.gridy = 0;
testPanel2.add(label2, c);
}
public static void main(String[] args) {
new Test();
}
}
在此代码中,有两个 JPanel,每个 JPanel 上都有一个 JLabel。第一个面板的底部有边框,第二个面板位于下方。您可以通过在 JFrame 上设置布局来做到这一点。您可以采用这个想法来处理您的代码。
使用您的代码,它看起来像这样。
Admin_main
import javax.swing.*;
public class Admin_main {
public static void main(String[] args) {
Admin_hs adm= new Admin_hs();
adm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
adm.pack();
adm.setVisible(true);
}
}
Admin_hs
import javax.swing.*;
import java.awt.*;
public class Admin_hs extends JFrame {
JButton bking_btn= new JButton("Bookings");
JButton fd_btn= new JButton("Financial Data");
JButton ctm_btn= new JButton("Customers");
JButton room_btn= new JButton("Rooms");
JButton adc_btn= new JButton("Additional Costs");
JButton endb_btn= new JButton("Ending Bookings");
//Images
JLabel bking_img= new JLabel();
JLabel fd_img= new JLabel();
JLabel ctm_img= new JLabel();
JLabel room_img= new JLabel();
JLabel adc_img= new JLabel();
JLabel endb_img= new JLabel();
JLabel copyrightL = new JLabel("Hotel Management System \u00a9 2016");
///Panels
JPanel pnl1 = new JPanel(new GridBagLayout()), pnl2 = new JPanel(new GridBagLayout());
///Constructors
public Admin_hs(){
setTitle("Welcome Admin!");
setLayout(new GridBagLayout());
///Setting a layout
pnl1.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill= GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(6, 6, 6, 6);
gbc.weightx = 1;
gbc.weighty = 1;
gbc.gridx = 0;
gbc.gridy = 0;
pnl1.add(bking_btn, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
pnl1.add(fd_btn, gbc);
gbc.gridx = 0;
gbc.gridy = 2;
pnl1.add(ctm_btn, gbc);
gbc.gridx = 0;
gbc.gridy = 3;
pnl1.add(room_btn, gbc);
gbc.gridx = 0;
gbc.gridy = 4;
pnl1.add(adc_btn, gbc);
gbc.gridx = 0;
gbc.gridy = 5;
pnl1.add(endb_btn, gbc);
/////second column of grid
gbc.weightx = 0;
gbc.fill= GridBagConstraints.BOTH;
ImageIcon icon = new ImageIcon("Smiley.gif");
Image image2 = icon.getImage().getScaledInstance(50, 50, 0);
ImageIcon icon2 = new ImageIcon(image2);
gbc.gridx = 1;
gbc.gridy = 0;
bking_img.setIcon(icon2);
pnl1.add(bking_img, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
fd_img.setIcon(icon2);
pnl1.add(fd_img, gbc);
gbc.gridx = 1;
gbc.gridy = 2;
ctm_img.setIcon(icon2);
pnl1.add(ctm_img, gbc);
gbc.gridx = 1;
gbc.gridy = 3;
room_img.setIcon(icon2);
pnl1.add(room_img, gbc);
gbc.gridx = 1;
gbc.gridy = 4;
adc_img.setIcon(icon2);
pnl1.add(adc_img, gbc);
gbc.gridx = 1;
gbc.gridy = 5;
endb_img.setIcon(icon2);
pnl1.add(endb_img, gbc);
pnl1.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
gbc.insets = new Insets(0, 0, 0, 0);
gbc.gridwidth = 1;
gbc.weightx = 1.0;
gbc.gridx = 0;
gbc.gridy = 0;
add(pnl1, gbc);
gbc.fill= GridBagConstraints.HORIZONTAL;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
pnl2.add(copyrightL, gbc);
gbc.weightx = 0;
gbc.gridx = 0;
gbc.gridy = 1;
add(pnl2, gbc);
}
}
这会产生这个
关于Java Swing-在 GridBagLayout 中的单行底部边框下方添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35649174/
我正在使用matplotlib创建简单的线图。我的图是一个简单的时间序列数据集,其中我沿x轴有时间,而我在y轴上有测量的值。 y值可以具有正值或负值,如果y值> 0,则我想用蓝色填充行上方和下方的颜色
我有一个简单的菜单,当单击菜单项时,该菜单会滚动到某个部分。 例如: Contact 将滚动到: 但是我也有一个始终粘在顶部的菜单,并且该菜单的高度不是用滚动脚本计算的。因此菜单总是悬停在元素的顶部
我有一个 UISearchBar 和 UISearchDisplayController,一切都很好,但我的范围选择器显示在文本字段旁边而不是下方。我知道这是设备横向时的预期操作,但由于我在 UISp
因此,我正在创建一个根据用户输入增大和缩小的 ListView ,我需要四个按钮,但我不知道如何让按钮与 ListView 的底部对齐并位于2x2 网格时尚。我已经尝试过相对布局,但似乎不起作用。谢谢
我正在使用的系统无法直接编辑每个页面上的 HTML。我想添加特定页面正文的顶部,但我输入 HTML 的框会自动将脚本放置在上面 我尝试过这个: $('body').prepend(''); 任何帮
设计模式一切都很好,但在实时导航栏位于 ScrollView 下方我该如何解决这个问题?请帮忙 最佳答案 同样,在没有看到任何代码的情况下很难说,但我相信导航栏根本没有显示。如果您直接从另一个 Vie
我现在必须重用和修改其他人的代码来创建图像处理应用程序。以下代码用于设置框架及其 GUI。我遇到的问题是,当在菜单栏上单击文件字时,菜单项列在 originalImage 容器中包含的 Canvas
我创建了一个 Angular 指令,用户可以在其中根据一天中的时间更改某些设置。下面是我已有的图片: 我想在 div 的 x 轴上添加一种准确表示时间的“滴答”,以向用户显示他在做什么,如下图所示:
这是下面的代码。 body { font-family: "Lato", sans-serif; } .sidenav { width: 130px; positio
这个问题在这里已经有了答案: Z-Index not working? [closed] (1 个回答) 关闭 5 年前。
我搜索了这个并尝试了 Z 轴的东西,但无济于事。基本上,我的导航栏在其下方的 div 下方显示有子菜单。那个 div 发生了不透明的事情,这一定与它有关。我需要这些显示在 div 上方!! JS fi
我正在处理的网站的某些页面使用脚本自动创建基于页面标题的目录。但是,我在获取“toc”div 以将页面的其余内容推送到其下方时遇到了一些问题。 TOC div 在我页面的最里面的 div 中,“con
我的代码 http://jsfiddle.net/p796z/1/ HTML Content Content Content Content Content Content
请看下面的代码: Button dropdown
我有一个表格,我希望它直接位于 Logo 下方位于页面中间。到目前为止,我似乎做不到更有什者。任何帮助将不胜感激。谢谢。 这是 HTML 代码:
我的 web 应用程序在与 jQuery Mobile 和 cordova 的聊天部分出现问题。我决定用 textaera 和发送消息的按钮修复页脚。但是当我触摸文本区域写消息时,我的键盘没有出现。我
我有两个来回箭头,可以单击它们在我的单页网站上的框架中浏览照片。我的术语在这里可能不正确。保存照片和前后箭头的 div 出现在我的屏幕下方,而不是在屏幕场景 div 中。我可以将图像向上移动以出现在屏
我使用自定义 CSS 和 Bootstrap 类名称构建了这个 header 。我已经尝试了 z-index、float: initial 属性。提前致谢 .branding-preview {
我有两个部分介绍网站上的用例和好处。如下。 .onboardmessaging { min-width: 100%; } .onboardmessagingwrap { min-wi
所以,我在网站上发现了这个很酷的 css/html slider ,所以我下载了代码,并打算研究它。我已经开始根据自己的需要对其进行编辑和设计,然后我遇到了这个问题:当我添加比原始尺寸更大的图像时,导
我是一名优秀的程序员,十分优秀!