我有一个使用FlowLayout的JPanel.我向JPanel添加了许多JLabel,使用setPreferedSize()调整它们的大小并将它们保存在list_list列表中.一切正常.然后我想改变它们的大小:
for(JLabel c:label_list){
c.setPreferedSize(new Dimension(10,10));
}
Run Code Online (Sandbox Code Playgroud)
它不起作用.
c.setBackground(Color.red)
Run Code Online (Sandbox Code Playgroud)
和类似的东西工作.为什么我不能在这里使用setPreferedSize?
c.setBounds(1,1,10,10)和c.setSize(10,10)工作,但在我更新UI(调整面板大小)后,每个尺寸都恢复正常.
我有一个带有QScrollArea小部件的ui 。在QScrollArea使用的FlowLayout。我的问题是,当我将小部件添加到布局中时,滚动区域开始滚动并且在有扩展空间时不会扩展。我希望在滚动条首先出现之前将滚动区域扩展到其极限。
如何在滚动条出现之前扩大滚动区域?
我有一个UICollectionView包含在UIViewController使用水平UICollectionViewFlowLayout.我也在使用我的原型单元格UIStoryboard.我想创建一个自定义分页,所以我正在使用- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset.
问题是,每当我尝试获取indexPathtargetContentOffset(滚动视图中滚动停止的点)时,即使该点明显位于集合视图contentSize内,集合视图也会返回nil.
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
NSIndexPath *indexPath = [_collectionView indexPathForItemAtPoint:(*targetContentOffset)];
// Do something with indexPath
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有一个带有两个自定义面板的表单,我正在为它们添加一些标签,最后我希望它们从右向左滚动,但它们只是在相同的位置.有我的截图
有两个面板和4个标签,它们只是停留在那里......这是我的表格中的代码:
private MyPanel topPanel; // the red bar
private MyPanel botPanel; // the white bar
public SmsBar()
{
InitializeComponent();
this.Width = 500000;
this.Location = new Point(x, y);
topPanel = new MyPanel(System.Drawing.Color.White, System.Drawing.Color.Red, (new Font("Tahoma", 10, FontStyle.Bold)));
botPanel = new MyPanel(System.Drawing.Color.Black, System.Drawing.Color.White, (new Font("Tohama", 10, FontStyle.Regular)));
msgPanel.Controls.Add(topPanel);
adPanel.Controls.Add(botPanel);
botPanel.addMsg(new MsgForDisplay(0, AppData.getInstance().getAdMsg()));
botPanel.addMsg(new MsgForDisplay(0, AppData.getInstance().getAdMsg2()));
topPanel.addMsg(new MsgForDisplay(0, "test top"));
topPanel.addMsg(new MsgForDisplay(0, "test top 2"));
adPanel.Refresh();
msgPanel.Refresh();
}
Run Code Online (Sandbox Code Playgroud)
并且我的自定义面板(构造函数)有一些代码:
public MyPanel(Color corLabel, Color back, Font text){
this.color = corLabel;
this.backg …Run Code Online (Sandbox Code Playgroud) 我的问题:JSpinner非常瘦,我只能在最后一个位置看到字符串上的字符.
例如:"你好"我只看到'o'.
我在JFrame的BorderLayout.SOUTH中有一个JPanel
JPanel的布局管理器是默认的 - 如果我被误导,请纠正我 - 一个FlowLayout管理器.
前面提到的JPanel中还有多个组件.
我试过了
RandomSpinner = new JSpinner(tempModel);
int w = RandomSpinner.getWidth(); int h = RandomSpinner.getHeight();
RandomSpinner.setSize(new Dimension(w * 2, h));
add(RandomSpinner);
Run Code Online (Sandbox Code Playgroud)
这对JSpinner的宽度没有影响.
我应该如何更改JSpinner的宽度或者这是一个FlowLayout问题?
谢谢
更新Xcode 7.0.1后,每次崩溃时我都无法打开我的工作区.阅读完所有这些文字后,我理解它是关于集合视图的流程布局,以及一些负面价值.假设我没有机会回到Xcode 6.有没有人有类似的问题,或者知道如何解决这个问题?
例外:
negative sizes are not supported in the flow layout
Run Code Online (Sandbox Code Playgroud)
关于我的工作区:
运用
OS OS X 10.11(macosx10.11):
这是崩溃日志:
XCODE版本信息:
Version = 7.0.1(7A1001)插件版本= 8191 Beta版本= 0 OS版本= 10.10.5(14F27)
断言:
无法确定IBUICollectionView的ibLayoutInset,intrinsicContentSize,baselineOffsetFromBottom,firstBaselineOffsetFromTop,ibLayoutMargins,ibContentSize,ibCellFrames,ibSectionHeaderViewFrames,ibSectionFooterViewFrames和ibBackgroundViewFrame的值.
异常名称:NSInternalInconsistencyException异常原因:流布局中不支持负大小异常回溯:0.CoreFoundation 0x00000001033d5f4d __exceptionPreprocess 1. libobjc.A.dylib 0x0000000102e4fdeb objc_exception_throw
CoreFoundation 0x00000001033d5dca + [NSExceptionraise:format:arguments:]
基础0x0000000102a9dae2 - [NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
UIKit 0x00000001010db6ff - [UICollectionViewFlowLayout _getSizingInfos]
- UIKit 0x00000001010dcef5 - [UICollectionViewFlowLayout _fetchItemsInfoForRect:]
- UIKit 0x00000001010d669d - [UICollectionViewFlowLayout prepareLayout]
- UIKit 0x00000001010f6ef1 - [UICollectionViewData _prepareToLoadData]
- UIKit 0x00000001010f767a - [UICollectionViewData validateLayoutInRect:]
UIKit 0x00000001010a883e - [UICollectionView layoutSubviews] …
我正在使用FlowLayout,我希望我的组件从框架的左上角"流动"到右下角,而不是从屏幕的中心开始.GridLayout做得很好,但它重新调整了我的组件的大小,我不喜欢这样.我会使用GridBagLayout,但它是如此复杂,我想看看如果有可能用FlowLayout做我想要的.
有人可以向我解释一下,为什么每次我使用FlowLayout布局管理器时,我的文本字段都显示为切口.
一段时间以来,我已经突然反对这个问题了,我似乎无法弄清楚为什么会出错.
我觉得这是一件很简单的事情,我一次又一次地忽略了,所以如果有人愿意向我解释这个现象,我将永远感激不尽.
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Console
{
public Console()
{
makeConsole();
}
private void makeConsole()
{
JFrame console = new JFrame("ArchiveConsole");
Container base = console.getContentPane();
base.setSize(400, 250);
console.setSize(base.getSize());
base.setLayout(new FlowLayout(FlowLayout.CENTER, 5,5));
JTextField tf = new JTextField();
tf.setSize(base.getWidth(), 25);
base.add(tf);
console.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud) 我想把我放在JLabel中的图像定位.这是我的代码:
public Main() {
setLayout (new FlowLayout());
image = new ImageIcon(getClass().getResource("title.gif"));
image1 = new JLabel(image);
image1.setAlignmentX(400);
image1.setAlignmentY(400);
add(image1);
}
Run Code Online (Sandbox Code Playgroud)
它显示图像,但显示线条
image1.setAlignmentX(400);
image1.setAlignmentY(400);
Run Code Online (Sandbox Code Playgroud)
不要做任何事情.我是Java的新手,感谢任何帮助.
(我希望得到一个例子.)
我使用WrapLayoutextends FlowLayout
现在,我有了这个 GUI:
我想要的是这样的:
我尝试了一些类似的事情:label.setVerticalAlignment(JLabel.TOP);但布局似乎不尊重它。我猜这种行为是继承自FlowLayout?
完整代码:
public class WrapLayoutExample {
public static void main(String[] args) {
SwingUtilities.invokeLater(WrapLayoutExample::runGui);
}
private static void runGui() {
JFrame frame = new JFrame("A");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new WrapLayout());
JLabel l = new JLabel("CCC");
l.setBorder(BorderFactory.createLineBorder(Color.red, 10));
l.setVerticalAlignment(JLabel.TOP);
panel.add(l);
l = new JLabel("BBBB");
l.setBorder(BorderFactory.createLineBorder(Color.red, 20));
panel.add(l);
frame.setLayout(new BorderLayout());
frame.add(new JScrollPane(panel));
frame.pack();
frame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud) flowlayout ×10
java ×6
swing ×5
ios ×2
jlabel ×2
c# ×1
c++ ×1
crash ×1
iphone ×1
jspinner ×1
jtextfield ×1
labels ×1
layout ×1
qscrollarea ×1
qt ×1
scroll ×1
storyboard ×1
xcode7 ×1